-
Course Overview 0
No items in this section -
Numerical 48
TCS-NQT Instructions : You will be given 26 Question with a time limit of 40 mins | Questions - 26 | Time - 40 mins
-
Lecture2.1
-
Lecture2.2
-
Lecture2.3
-
Lecture2.4
-
Lecture2.5
-
Lecture2.6
-
Lecture2.7
-
Lecture2.8
-
Lecture2.9
-
Lecture2.10
-
Lecture2.11
-
Lecture2.12
-
Lecture2.13
-
Lecture2.14
-
Lecture2.15
-
Lecture2.16
-
Lecture2.17
-
Lecture2.18
-
Lecture2.19
-
Lecture2.20
-
Lecture2.21
-
Lecture2.22
-
Lecture2.23
-
Lecture2.24
-
Lecture2.25
-
Lecture2.26
-
Lecture2.27
-
Lecture2.28
-
Lecture2.29
-
Lecture2.30
-
Lecture2.31
-
Lecture2.32
-
Lecture2.33
-
Lecture2.34
-
Lecture2.35
-
Lecture2.36
-
Lecture2.37
-
Lecture2.38
-
Lecture2.39
-
Lecture2.40
-
Lecture2.41
-
Lecture2.42
-
Lecture2.43
-
Lecture2.44
-
Lecture2.45
-
Lecture2.46
-
Lecture2.47
-
Lecture2.48
-
-
Verbal 10
TCS-NQT Instructions : You will be given 24 Question with a time limit of 30 mins | Questions - 24 | Time - 15 mins + 30 mins
-
Lecture3.1
-
Lecture3.2
-
Lecture3.3
-
Lecture3.4
-
Lecture3.5
-
Lecture3.6
-
Lecture3.7
-
Lecture3.8
-
Lecture3.9
-
Lecture3.10
-
-
Aptitude Series for Placement [ Free Sample Videos ] 16
Note: TCS NQT Study Material Doesn't Contain videos we provide only Study Materials in this course , these videos are sample videos of our Aptitude Series
-
Lecture4.1
-
Lecture4.2
-
Lecture4.3
-
Lecture4.4
-
Lecture4.5
-
Lecture4.6
-
Lecture4.7
-
Lecture4.8
-
Lecture4.9
-
Lecture4.10
-
Lecture4.11
-
Lecture4.12
-
Lecture4.13
-
Lecture4.14
-
Lecture4.15
-
Lecture4.16
-
-
Reasoning 21
TCS-NQT Instructions : You will be given 30 Question with a time limit of 50 mins | Questions - 30 | Time - 50 mins
-
Lecture5.1
-
Lecture5.2
-
Lecture5.3
-
Lecture5.4
-
Lecture5.5
-
Lecture5.6
-
Lecture5.7
-
Lecture5.8
-
Lecture5.9
-
Lecture5.10
-
Lecture5.11
-
Lecture5.12
-
Lecture5.13
-
Lecture5.14
-
Lecture5.15
-
Lecture5.16
-
Lecture5.17
-
Lecture5.18
-
Lecture5.19
-
Lecture5.20
-
Lecture5.21
-
-
Programming Logic 6
TCS-NQT Instructions : You will be given 10 Question with a time limit of 15 mins | Questions - 10 | Time - 15 mins
-
Lecture6.1
-
Lecture6.2
-
Lecture6.3
-
Lecture6.4
-
Lecture6.5
-
Lecture6.6
-
-
Coding 16
TCS-NQT Instructions : You will be given 2 Question with a time limit of 15 mins and 30 mins | Questions - 2 | Time - 15 mins + 30 mins
-
Lecture7.1
-
Lecture7.2
-
Lecture7.3
-
Lecture7.4
-
Lecture7.5
-
Lecture7.6
-
Lecture7.7
-
Lecture7.8
-
Lecture7.9
-
Lecture7.10
-
Lecture7.11
-
Lecture7.12
-
Lecture7.13
-
Lecture7.14
-
Lecture7.15
-
Lecture7.16
-
-
Previous Year Paper and Solution 2
-
Lecture8.1
-
Lecture8.2
-
Data Types
Which of the following is not a data type?
A) Symbolic Data | B) Alphanumeric Data |
C) Numeric Data | D) Alphabetic Data |
A) Symbolic Data
Explanation:
Data types are of three basic types: Numeric, Alphabetic and Alphanumeric. Numeric Data consists of only numbers. Alphabetic Data consists of only letters and a blank character and alphanumeric data consists of symbols.
*@Ac# is a type of ________________ data.
A) Symbolic | B) Alphanumeric |
C) Alphabetic | D) Numeric |
B) Alphanumeric
Explanation:
Alphanumeric data consists of symbols. Alphanumeric data may be a letter, either in uppercase or lowercase or some special symbols like #,^,*,(, etc.
Which of the following is not a valid representation in bits?
A) 8-bit | B) 24-bit |
C) 32-bit | D) 64-bit |
B) 24-bit
Explanation:
There are no criteria like the 24-bit representation of numbers. Numbers can be written in 8-bit, 16-bit, 32-bit and 64-bit as per the IEEE format.
What are the entities whose values can be changed called?
A) Constants | B) Variables |
C) Modules | D) Tokens |
B) Variables
Explanation:
Variables are the data entities whose values can be changed. Constants have a fixed value. Tokens are the words which are easily identified by the compiler.
Which of the following is not a basic data type in C language?
A) float | B) int |
C) real | D) char |
C) real
Explanation:
There are 5 basic data types in C language: int, char, float, double, void. Int is for the representation of integers, char is for strings and characters, float and double are for floating point numbers whereas void is a valueless special data type.
Neelam wants to share her code with a colleague, who may modify it. Thus she wants to include the date of the program creation, the author and other with the program. What component should she use?
A) header files | B) iteration |
C) comments | D) pre processor |
C) comments
Which is used to convert source code to target language
A) Linker | B) Loader |
C) Executer | D) Compiler |
D) Compiler
A 10-bit unsigned integer has the following range:
A) 0 to 1000 | B) 0 to 1024 |
C) 0 to 1023 | D) 0 to 1025 |
C) 0 to 1023
Tricha wants to store a list of binary data.Which of following data types should she use?
A) Boolean | B) Integer |
C) Character | D) Floating |
A) Boolean
Which of the following options is an exception to being a part of composite data types?
A) Union | B) Structure |
C) Array | D) Stack |
B) Structure
Standard Input & Output – 1
What will be the final value of the res when INPUT N1=100?
Function F(INPUT N1)
Static int res=0;
IF(N1>0)
res=res+1
F(N1/20)
END IF
return res
END Function
A) 3 | B) 2 |
C) 1 | D) Error |
B) 2
What will be the output of the following pseudo code
Integer x,y,z
x=2
y=1
z=5
Do
Print z--
while((x & y)|| (z+1))
End loop
A) 543210 | B) 543211 |
C) 432100 | D) 432111 |
A) 543210
What is the output of the following code?
Set integer _no1=0, _no2=1, _no3=1, _lower=6, _inc=1
ile _inc is less than equals to _lower:
_inc is increment by 1
Print _no3
_no3=_no1+_no2
_no1 equals to _no2
_no2 equals to _no3
End While
A) 12358 | B) 358 |
C) 112358 | D) 2358 |
C) 112358
Find the output of the following code
#include
t main ()
int num;
printf ("enter number" );
scanf ("%d", &num);
no = (num * 2) + 3 ;
(no & 1 && printf ("odd"))printf ("even")
return 0;
}
A) Enter a number : Odd | B) Odd |
C) Error: 'no' undeclared | D) even |
C) Error: 'no' undeclared
What will be the output of the following code?
#include
int main()
{
while(){
printf(“hello world”);
}
return 0;
}
A) Compile error | B) No output will be Printed |
C) hello world | D) Infinite loop |
A) Compile error
Which among the following is the odd one out?
A) printf | B) fprintf |
C)putchar | D) scanf |
D) scanf
For a typical program, the input is taken using _________
A) scanf | B) Files |
C) Command-line | D) All of the mentioned |
D) All of the mentioned
What does the following command line signify?
prog1|prog2
A) It runs prog1 first, prog2 second | B) It runs prog2 first, prog1 second |
C) It runs both the programs, pipes output of prog1 to input of prog2 | D) It runs both the programs, pipes output of prog2 to input of prog1 |
C) It runs both the programs, pipes output of prog1 to input of prog2r
What is the default return-type of getchar()?
A) char | B) int |
C) char * | D) reading character doesn’t require a return-type |
B) int
What is the value of EOF?
A) -1 | B) 0 |
C) 1 | D) 10 |
A) -1
Scope of a Variable – 1
What will be the output of the following C code?
#include
A) scope rules | B) Compile time error due to multiple declaration |
C) Compile time error due to not defining type in statement extern i | D) Nothing will be printed as value of i is not zero because i is an automatic variable |
A) scope rules
What will be the output of the following C code (without linking the source file in which ary1 is defined)?
#include
A) scope rules | B) Linking error due to undefined reference |
C) Compile time error because size of array is not provided | D) Compile time error because datatype of array is not provided |
A) scope rules
What will be the output of the following C code (after linking to source file having definition of ary1)?
#include
A) Value of ary1[0]; | B) Compile time error due to multiple definition |
C) Compile time error because size of array is not provided | D) Compile time error because datatype of array is not provided |
D) Compile time error because datatype of array is not provided
What is the scope of an external variable?
A) Whole source file in which it is defined | B) From the point of declaration to the end of the file in which it is defined |
C) Any source file in a program | D) From the point of declaration to the end of the file being compiled |
D) From the point of declaration to the end of the file being compiled
What is the scope of a function?
A) Whole source file in which it is defined | B) From the point of declaration to the end of the file in which it is defined |
C) Any source file in a program | D) From the point of declaration to the end of the file being compiled |
D) From the point of declaration to the end of the file being compiled
What is the use of getchar()?
A) The next input character each time it is called | B) EOF when it encounters end of file |
C) The next input character each time it is called EOF when it encounters end of file | D) None of the mentioned |
C) The next input character each time it is called EOF when it encounters end of file
Which of the following statement is true?
A) The symbolic constant EOF is defined in |
B) The value is -1 |
C) The symbolic constant EOF is defined in |
D) Only value is -1 |
C) The symbolic constant EOF is defined in
What is the return value of putchar()?
A) The character written | B) EOF if an error occurs |
C)Nothing | D) Both character written & EOF if an error occurs |
D) Both character written & EOF if an error occurs
Which of the following accessibility modes can be the specifier of a top level class’ ?
A) only Private | B) Protected and Private |
C) Public and Modifier | D) only no modifier |
C) Public and Modifier
Anu wants to make a function that is not bound to any identifier. Which of the following functions should she incorporate in her program?
A) Global Function | B) Friend Function |
C) Anonymous Function | D) Null Function |
C) Anonymous Function
Register Variables – 1
What will be the output of the following C code?
#include
int main()
{
register int i = 10;
int *p = &i;
*p = 11;
printf("%d %d\n", i, *p);
}
A) Depends on whether i is actually stored in machine register | B) 10 10 |
C) 11 11 | D)Compile time error |
D)Compile time error
register keyword mandates compiler to place it in machine register.
A) True | B) False |
C) Depends on the standard | D)None of the mentioned |
B) False
What will be the output of the following C code?
#include
int main()
{
register static int i = 10;
i = 11;
printf("%d\n", i);
}
A) 10 | B) Compile time error |
C) Undefined behaviour | D) 11 |
B) Compile time error
What will be the output of the following C code?
#include
int main()
{
register auto int i = 10;
i = 11;
printf("%d\n", i);
}
A) 10 | B) Compile time error |
C) Undefined behaviour | D) 11 |
B) Compile time error
What will be the output of the following C code?
#include
int main()
{
register const int i = 10;
i = 11;
printf("%d\n", i);
}
A)10 | B) Compile time error |
C) Undefined behaviour | D) 11 |
B) Compile time error
Register storage class can be specified to global variables.
A) True | B) False |
C) Depends on the compiler | D) Depends on the standard |
B) False
Which among the following is wrong for “register int a;”?
A) Compiler generally ignores the request | B) You cannot take the address of this variable |
C) Access time to a is critical | D) None of the mentioned |
D) None of the mentioned
What will be the output of the following C code?
void main()
{
register int x = 5;
m();
printf("x is %d", x);
}
void m()
{
x++;
}
A) 6 | B) 5 |
C) Junk value | D) Compile time error |
D) Compile time error
What is the term given to the variable whose scope is beyond all the scopes i.e., it can be accessed by all the scopes?
A) Universal Variable | B) Global Variable |
C) External Variable | D) Auto Variable |
B) Global Variable
Which of the following accessibility modes can be the specifier of a top level class’ ?
A) Only Private | B) Protected and Private |
C) Public and no Modifier | D) Only no Modifier |
C) Public and no Modifier
Command Line Arguments
What does argc and argv indicate in command-line arguments? (Assuming: int main(int argc, char *argv[]) )
A) argument count, argument variable | B)argument count, argument vector |
C)argument control, argument variable | D) argument control, argument vector |
B)argument count, argument vector
Which of the following syntax is correct for command-line arguments?
A) int main(int var, char *varg[]) |
B) int main(char *argv[], int argc) |
C) int main()
|
D) none of the mentioned |
A)
int main(int var, char *varg[])
In linux, argv[0] by command-line argument can be occupied by _________
A) ./a.out | B) ./test |
C) ./fun.out.out | D)all of the mentioned |
D)all of the mentioned
Explanation:
All the options mentioned (./a.out, ./test, ./fun.out.out) are simply the command without any argument. A command is always stored as argument vector zero i.e., argv[0] always contain the command where as argv[1], argv[2], etc. contains the arguments to the commands, if any.
What type of array is generally generated in Command-line argument?
A) Single dimension array | B) 2-Dimensional Square Array |
C) Jagged Array | D)2-Dimensional Rectangular Array |
C) Jagged Array
What will be the output of the following C statement? (assuming the input is “cool brother in city”)
printf(“%s\n”, argv[argc]);
A) (null) | B) City |
C) In | D) Segmentation Fault |
A) (null)
What is the first argument in command line arguments?
A) The number of command-line arguments the program was invoked with; | B) A pointer to an array of character strings that contain the arguments |
C) Nothing | D) None of the mentioned |
A) The number of command-line arguments the program was invoked with;
What is the second argument in command line arguments?
A) The number of command-line arguments the program was invoked with; | B) A pointer to an array of character strings that contain the arguments, one per string |
C)Nothing | D) None of the mentioned |
B) A pointer to an array of character strings that contain the arguments, one per string
What is argv[0] in command line arguments?
A) The name by which the program was invoked | B) The name of the files which are passed to the program |
C) Count of the arguments in argv[] vector | D)None of the mentioned |
A) The name by which the program was invoked
What argv means in command line argument ?
A) Array of Pointers | B) Pointer to a Character array |
C) Array of character Pointers | D) Array of Strings |
C) Array of character Pointers
Which one of these is equivalent to argc ?
A) Number of Arguments | B) Number of Arguments -1 |
C) Number of Arguments +2 | D) Number of Arguments +1 |
D) Number of Arguments +1
Inbuilt Libraries (based on C)
What will the code display on compiling?
void funccall()
{
printf("this is funccall\n");
}
void main ()
{
atexit(funccall);
printf("program starts\n");
printf("program ends\n");
}
A) program starts
this is funccall program ends |
B) this is funccall
program starts program ends |
C) program starts
program ends this is funccall |
D) error |
C) program starts program ends this is funccall
Explanation:
int atexit(void (*func)(void)) calls the specified function func when the program terminates. we can register termination function anywhere in the program, but it will be called at the time of the program termination.
What will be the output of the following C code?
int main ()
{
printf("starting of program\n");
printf("program exits\n");
exit(0);
printf("program ends\n");
return(0);
}
A) starting of program
program exits program ends |
B) starting of program
program exits |
C) starting of program
program ends |
D) error |
B) starting of program program exits
Explanation:
void exit(int status) function is used to terminate the calling process immediately.
What will be the output of the following C code?
void main ()
{
char com[50];
strcpy( com, "dir" );
system(com);
}
A) error | B) lists down all the files and directories in the current directory under windows machine |
C) terminates the calling process immediately | D) calls specified function and terminates it at the end of the program |
B) lists down all the files and directories in the current directory under windows machine
Explanation:
int system(const char *command) function is used to pass the command name or the program name specified by command to the host environment to be executed by the command processor and returns after the command has been completed.\
What will be the output of the following C code?
void main()
{
div_t res;
res = div(34, 4);
printf("quotient part = %d\n", res.quot);
printf("remainder part = %d\n", res.rem);
}
A) quotient part=0
remainder part=4 |
B) quotient part=8
remainder part=2 |
C) quotient part=4
remainder part=0 |
D) quotient part=2
remainder part=8 |
B) quotient part=8
remainder part=2
Explanation:
div_t div(int n, int d) used to divide n (numerator) by d (denominator).
div_t is a structure defined in
Initial seed is ________ for the function srand(unsigned int seed).
A) 0 | B) 1 |
C) 00 | D) 01 |
B) 1
Explanation:
void srand(unsigned int seed);
This function returns a new sequence of pseudo-random numbers using the specified seed.Initial seed is 1.
Which statement is true with respect to RAND_MAX?
A) specifies value for status argument to exit indicating failure | B) specifies value for status argument to exit indicating success |
C) specifies maximum value returned by rand() | D) specifies maximum value returned by srand() |
C) specifies maximum value returned by rand()
Explanation:
RAND_MAX specifies maximum value that has to returned by the function rand().
rand() function returns a pseudo-random number in the range 0 to RAND_MAX.
Which of the given function differs from the statement’errno is not neccessarily set on conversion error’?
A) atof() | B) atoi() |
C) atol() | D) strtod() |
D)atoi()
Explanation:
The function atoi() and atol() are similar to strtol(), atof() is similar to strtod() except that errono is not necessarily set on conversion error.
void free(void *p) performs which of the following functions?
A) returns pointer to allocated space for existing contents of p | B) de-allocates space to which p points |
C) to abnormally terminate the program | D) no such function defined in stdlib.h |
A) = operator is not a sequence point
What will be the output of the following C code?
#include
int main()
{
int i = 0;
int x = i++, y = ++i;
printf(“%d % d\n”, x, y);
return 0;
}
A) 0, 2 | B) 0, 1 |
C) 1, 2 | D) Undefined |
A) 0, 2
What does argc and argv indicate in command-line arguments?
(Assuming: int main(int argc, char *argv[]) )
A) argument count, argument variable | B) argument count, argument vector |
C) argument control, argument variable | D) argument control, argument vector |
B) argument count, argument vector
Pointers
What will be the output of the following C code?
#include
void foo(int*);
int main()
{
int i = 10;
foo((&i)++);
}
void foo(int *p)
{
printf("%d\n", *p);
}
A) 10 | B) Some garbage value |
C) Compile time error | D) Segmentation fault/code crash |
C) Compile time error
What will be the output of the following C code?
#include
void foo(int*);
int main()
{
int i = 10, *p = &i;
foo(p++);
}
void foo(int *p)
{
printf("%d\n", *p);
}
A) 10 | B) Some garbage value |
C) Compile time error | D) Segmentation fault/code crash |
A) 10
What will be the output of the following C code?
#include
void foo(float *);
int main()
{
int i = 10, *p = &i;
foo(&i);
}
void foo(float *p)
{
printf("%f\n", *p);
}
A) 10.000000 | B) 0.000000 |
C) Compile time error | D) Undefined behaviour |
B) 0.000000
What will be the output of the following C code?
#include
int main()
{
int i = 97, *p = &i;
foo(&i);
printf("%d ", *p);
}
void foo(int *p)
{
int j = 2;
p = &j;
printf("%d ", *p);
}
A) 2 97 | B) 2 2 |
C) Compile time error | D) Segmentation fault/code crash |
A) 2 97
What will be the output of the following C code?
#include
int main()
{
int i = 97, *p = &i;
foo(&p);
printf("%d ", *p);
return 0;
}
void foo(int **p)
{
int j = 2;
*p = &j;
printf("%d ", **p);
}
A) 2 97 | B) 2 2 |
C) Compile time error | D) Segmentation fault/code crash |
A) 2 97
What will be the output of the following C code?
#include
int main()
{
int i = 11;
int *p = &i;
foo(&p);
printf("%d ", *p);
}
void foo(int *const *p)
{
int j = 10;
*p = &j;
printf("%d ", **p);
}
A) Compile time error | B) 10 10 |
C) Undefined behaviour | D) 10 11 |
A) Compile time error
What will be the output of the following C code?
#include
int main()
{
int i = 10;
int *p = &i;
foo(&p);
printf("%d ", *p);
printf("%d ", *p);
}
void foo(int **const p)
{
int j = 11;
*p = &j;
printf("%d ", **p);
}
A) 11 11 11 | B) 11 11 Undefined-value |
C) Compile time error | D) Segmentation fault/code-crash |
B) 11 11 Undefined-value
What will be the output of the following C code?
#include
int main()
{
int i = 10;
int *const p = &i;
foo(&p);
printf("%d\n", *p);
}
void foo(int **p)
{
int j = 11;
*p = &j;
printf("%d\n", **p);
}
A) 11 11 | B) Undefined-value |
C) Compile time error | D) Segmentation fault/code-crash |
A) 11 11
Which of the following is the correct syntax to send an array as a parameter to function?
A) func(&array); | B) func(#array); |
C) func(*array); | D) func(array[size]); |
A) func(&array);
If a variable is a pointer to a structure, then which of the following operator is used to access data members of the structure through the pointer variable?
A) . | B) & |
C) * | D) -> |
D) ->
Call by value/reference
Passing object to a function _______________
A) Can be done only in one way | B) Can be done in more than one ways |
C) Is not possible | D) Is not possible in OOP |
B) Can be done in more than one ways
Explanation:
The objects can be passed to the functions and this requires OOP concept because objects are main part of OOP. The objects can be passed in more than one way to a function. The passing depends on how the object have to be used.
The object ________________
A) Can be passed by reference | B) Can be passed by value |
C) Can be passed by reference or value | D) Can be passed with reference |
C) Can be passed by reference or value
Explanation:
The objects can be passed by reference if required to use the same object. The values can be passed so that the main object remains same and no changes are made to it if the function makes any changes to the values being passed.
Which symbol should be used to pass the object by reference in C++?
A) & | B) @ |
C) $ | D) $ or & |
A) &
Explanation:
The object to be passed by reference to the function should be preceded by & symbol in the argument list syntax of the function. This indicates the compiler not to use new object. The same object which is being passed have to be used.
If object is passed by value ______________
A) Copy constructor is used to copy the values into another object in the function | B) Copy constructor is used to copy the values into temporary object |
C) Reference to the object is used to access the values of the object | D) Cannot be Reference to the object is used to created new object in its place |
A) Copy constructor is used to copy the values into another object in the function
Explanation:
The copy constructor is used. This constructor is used to copy the values into a new object which will contain all the values same as that of the object being passed but any changes made to the newly created object will not affect the original object.
Pass by reference of an object to a function _______________
A) Affects the object in called function only | B) Affects the object in prototype only |
C) Affects the object in caller function | D) Affects the object only if mentioned with & symbol with every call |
C) Affects the object in caller function
Explanation:
The original object in the caller function will get affected. The changes made in the called function will be same in the caller function object also.
Copy constructor definition requires __________________
A) Object to be passed by value | B) Object not to be passed to it |
C) Object to be passed by reference | D) Object to be passed with each data member value |
C) Object to be passed by reference
Explanation:
The object must be passed by reference to a copy constructor. This is to avoid the out of memory error. The constructors keeps calling itself, if not passed by reference, and goes out of memory.
What is the type of object that should be specified in the argument list?
A) Function name | B) Object name itself |
C) Caller function name | D) Class name of object |
D) Class name of object
Explanation:
The type of object is the class itself. The class name have to be specified in order to pass the objects to a function. This allows the program to create another object of same class or to use the same object that was passed.
If an object is passed by value, _________________
A) Temporary object is used in the function | B) Local object in the function is used |
C) Only the data member values are used | D) The values are accessible from the original object |
B) Local object in the function is used
Explanation:
When an object is called by values, copy constructor is called and object is copied to the local object of the function which is mentioned in the argument list. The values gets copied and are used from the local object. There is no need to access the original object again.
Can data members be passed to a function using the object?
A) Yes, it can be passed only inside class functions | B) Yes, only if the data members are public and are being passed to a function outside the class |
C) No, can’t be passed outside the class | D) No, can’t be done |
B) Yes, only if the data members are public and are being passed to a function outside the class
Explanation:
The data members can be passed with help of object but only if the member is public. The object will obviously be used outside the class. The object must have access to the data member so that its value or reference is used outside the class which is possible only if the member is public.
What exactly is passed when an object is passed by reference?
A) The original object name | B) The original object class name |
C) The exact address of the object in memory | D) The exact address of data members |
C) The exact address of the object in memory
Explanation:
The location of the object, that is, the exact memory location is passed, when the object is passed by reference. The pass by reference is actually a reference to the object that the function uses with another name to the same memory location as the original object uses.
Iteration
The C code ‘for(;;)’ represents an infinite loop. It can be terminated by ___________
A) break | B) exit(0) |
C) abort() | D) terminate |
A) break
What will be the correct syntax for running two variable for loop simultaneously?
A) for (i = 0; i < n; i++)
for (j = 0; j < n; j += 5) |
B) for (i = 0, j = 0; i < n, j < n; i++, j += 5) |
C) for (i = 0; i < n;i++){} for (j = 0; j < n;j += 5){} | D) none of the mentioned |
B) for (i = 0, j = 0; i < n, j < n; i++, j += 5)
Which for loop has range of similar indexes of ‘i’ used in for (i = 0;i < n; i++)?
A) for (i = n; i>0; i–) | B) for (i = n; i >= 0; i–) |
C) for (i = n-1; i>0; i–) | D) for (i = n-1; i>-1; i–) |
D) for (i = n-1; i>-1; i–)
Which of the following cannot be used as LHS of the expression in for (exp1;exp2; exp3)?
A) variable | B) function |
C) typedef | D) macros |
D) macros
What will be the output of the following C code?
#include
int main()
{
short i;
for (i = 1; i >= 0; i++)
printf("%d\n", i);
}
A) The control won’t fall into the for loop | B) Numbers will be displayed until the signed limit of short and throw a runtime error |
C) Numbers will be displayed until the signed limit of short and program will successfully terminate | D) This program will get into an infinite loop and keep printing numbers with no errors |
C) Numbers will be displayed until the signed limit of short and program will successfully terminate
Which is a general strategy for controlling how a computation evolves?
A) Recursion | B) Mapping |
C) Iteration | D) None of the mentioned |
C) Iteration
Explanation:
Iteration is said to be one kind of control strategy and it is a general strategy for controlling how a computation evolves.
What will be the output of the following C code?
#include
void main()
{
int k = 0;
for (k)
printf("Hello");
}
A) Compile time error | B) hello |
C) Nothing | D) Varies |
A) Compile time error
What will be the output of the following C code?
#include
void main()
{
int k = 0;
for (k < 3; k++)
printf("Hello");
}
A) Compile time error | B) hello |
C) Nothing | D) Varies |
A) Compile time error
What will be the output of the following C code?
#include
void main()
{
double k = 0;
for (k = 0.0; k < 3.0; k++)
printf("Hello");
}
A) Run time error | B) Hello is printed thrice |
C) Hello is printed twice | D) Hello is printed infinitely |
B) Hello is printed thrice
Explanation:
None
What will be the output of the following C code?
#include
void main()
{
int x = 5;
if (true);
printf(“hello”);
}
A) It will display hello | B) It will throw an error |
C) Nothing will be displayed | D) Compiler dependent |
B) It will throw an error
Explanation:
None.
Recursion
The data structure used to implement recursive function calls _____________
A) Array | B) Linked list |
C) Binary tree | D) Stack |
D) Stack
Explanation:
The compiler uses the data type stack for implementing normal as well as recursive function calls.
What will be the output of the following C code?
#include
main()
{
int n;
n=f1(4);
printf("%d",n);
}
f1(int x)
{
int b;
if(x==1)
return 1;
else
b=x*f1(x-1);
return b;
}
A) 24 | B) 4 |
C) 12 | D) 10 |
A) 24
Explanation:
The above code returns the factorial of a given number using the method of recursion. The given number is 4 in the above code, hence the factorial of 4, that is, 24 will be returned.
The principle of stack is __________
A) First in first out | B) First in last out |
C) Last in first out | D) Last in last out |
C) Last in first out
Explanation:
A stack is a last in first out(LIFO) data type. This means that the last item to get stored in the stack is the first item to get out of it.
In the absence of a exit condition in a recursive function, the following error is given __________
A) Compile time error | B) Run time error |
C) Logical error | D) No error |
B) Run time error
Explanation:
When a recursive function is called in the absence of an exit condition, it results in an infinite loop due to which the stack keeps getting filled(stack overflow). This results in a run time error.
What will be the output of the following C code?
#include
main()
{
int n,i;
n=f(6);
printf("%d",n);
}
f(int x)
{
if(x==2)
return 2;
else
{
printf("+");
f(x-1);
}
}
A) ++++2 | B) +++++2 |
C) +++++ | D) 2 |
A) ++++2
Explanation:
When x=6: ‘+’ is printed. When x=5: ‘+’ is printed. When x=4: ‘+’ is printed. When x=3: ‘+’ is printed. When x=2: 2 is printed. Hence the output is: ++++2.
How many times is ‘a’ printed when the following C code is executed?
#include
main()
{
int a;
a=f1(10);
printf("%d",a);
}
f1(int b)
{
if(b==0)
return 0;
else
{
printf("a");
f1(b--);
}
}
A) 9 times | B) 10 times |
C) 0 times | D) Infinite number of times |
D) Infinite number of times
Explanation:
Although we have specified the exit condition, the code above results in an infinite loop because we have used b- -(decrement operator) to call the recursive function. Due to this, the loop goes on infinitely. However, if we had used f1(b-1) instead, the answer would have been 10 times.
What will be the output of the following C code?
#include
main()
{
int n=10;
int f(int n);
printf("%d",f(n));
}
int f(int n)
{
if(n>0)
return(n+f(n-2));
}
A) 10 | B) 80 |
C) 30 | D) Error |
C) 30
Explanation:
The recursive function returns n+f(n-2) till 10>0. Therefore, the above code will be evaluated as: 10+8+6+4+2, which is equal to 30.
What will be the output of the following C code?
'
#include
int main()
{
printf("Hello");
main();
return 0;
}
A) Hello is printed once | B) Hello infinite number of times |
C) Hello is not printed at all | D) 0 is returned |
A) nside if
Explanation:
None
What will be the output of the following C code if the input given to the code shown below is “sanfoundry”?
#include
#define NL '\n'
main()
{
void f(void);
printf("enter the word\n");
f();
}
void f(void)
{
char c;
if((c=getchar())!=NL)
{
f();
printf("%c",c);
}
return;
}
A) sanfoundry | B) infinite loop |
C) yrdnuofnas | D) fnasyrdnuo |
C) yrdnuofnas
Explanation:
The above code prints the reverse of the word entered. The recursive function terminates when getchar() is equal to null.
Iteration requires more system memory than recursion.
A) True | B) False |
B) False
Explanation:
Recursion requires more system memory than iteration due to the maintenance of stack.