1.
What will be the output of the following program?
#include<stdio.h>
int main()
{
char numbers[5][6] = {"Zero","One","Two","Three","Four"};
printf("%s is %c",&numbers[4][0],numbers[0][0]);
return 0;
}
Correct Answer
A. Four is Z
Explanation
The program declares a 2D array of characters called "numbers" with 5 rows and 6 columns. It initializes the array with the strings "Zero", "One", "Two", "Three", and "Four".
In the printf statement, it prints the character at the first index of the string in the 5th row of the array (which is 'F') and the character at the first index of the string in the 1st row of the array (which is 'Z').
Therefore, the output of the program will be "Four is Z".
2.
Which one of the following is an example of storage class in C?
Correct Answer
B. Extern
Explanation
The correct answer is "extern" because it is a storage class in C. The "extern" keyword is used to declare a variable or function that is defined in another file or module. It is used to provide a reference to a global variable or function that is defined in a separate source file.
3.
What will be the output of the following program?
#include<stdio.h>
int main()
{
int a = 1, b = 2, c = 3;
printf("The value of a is %d", ++a);
func();
printf(" The value of a is %d", ++a);
return 0;
}
void func()
{
int a = 10;
return 0;
}
Correct Answer
B. The value of a is 2 The value of a is 3
Explanation
The output of the program will be "The value of a is 2 The value of a is 3". This is because the variable "a" is incremented twice using the pre-increment operator (++a) before each printf statement. The first printf statement is executed immediately after the increment, so it prints the value of "a" as 2. Then, the function func() is called, but it does not affect the value of "a". Finally, the second printf statement is executed, printing the value of "a" as 3.
4.
What is the output of the below program?
#include<stdio.h>
int main()
{
printf("%c", "abcdefgh"[6]);
return 0;
}
Correct Answer
A. G
Explanation
The program uses array indexing to access the 6th character of the string "abcdefgh", which is 'g'. Therefore, the output of the program is 'g'.
5.
What will be the output of the following program?
#include<stdio.h>
#define putchar(c) printf("%c",c)
int main()
{
char s='c';
putchar (s);
return 0;
}
Correct Answer
D. C
Explanation
The program includes the header file "stdio.h" and defines a macro "putchar(c)" which is equivalent to the printf statement "%c". In the main function, a character variable "s" is assigned the value 'c'. The putchar function is then called with the argument "s". Since putchar prints the character value passed to it, the output of the program will be the character 'c'.
6.
What will be the output of the following program?
#include<stdio.h>
enum {TRUE, FALSE};
int main()
{
int i=1;
do{
printf("%d\t",i);
i++;
if(i > 5)
break;
}
while(TRUE);
return 0;
}
Correct Answer
D. 1
Explanation
The program uses a do-while loop to print the value of the variable "i" and then increments it. It checks if "i" is greater than 5 and if so, it breaks out of the loop. Since the condition for the loop to continue is "TRUE" and it is not changed within the loop, the loop will continue indefinitely. Therefore, the program will print an infinite loop of numbers starting from 1.
7.
What will be the output of the following program ?
#include<stdio.h>
int main(){
typedef struct{char ch;}st;
st s1 = {'c'}; st s2 = s1;
if(s1 == s2)
printf("Successful");
return 0;
}
Correct Answer
B. Compiler error
Explanation
The program will result in a compiler error. This is because the comparison operator "==" cannot be used to compare two struct variables.
8.
What is the keyword used to turn off the compiler optimization of a variable?
Correct Answer
B. Volatile
Explanation
The keyword "volatile" is used to turn off the compiler optimization of a variable. When a variable is declared as volatile, it indicates to the compiler that the value of the variable may change unexpectedly, and therefore the compiler should not optimize any code that involves that variable. This is useful in situations where the variable is accessed by multiple threads or in situations where the variable is modified by hardware or other external factors. By using the "volatile" keyword, the programmer ensures that the variable is always read from and written to memory, rather than being cached or optimized by the compiler.
9.
What will be the output of the following program?
#include<stdio.h>
int main()
{
fun();
}
fun()
{
printf("you are in fun");
main();
return 0;
}
Correct Answer
D. Stack overflow
Explanation
The program will enter into an infinite loop because the function "fun" is calling the "main" function recursively without any termination condition. This will lead to the stack getting filled with function calls, eventually causing a stack overflow. As a result, the program will not be able to execute any further instructions and will terminate abruptly.
10.
Which one of the following is the correct way of declaring main() function when it receives command line arguments?
Correct Answer
D. Main(int argc,char* argv[ ])
Explanation
The correct way of declaring the main() function when it receives command line arguments is "main(int argc,char* argv[ ])". This declaration specifies that the main() function takes two arguments - an integer "argc" which represents the number of command line arguments passed, and an array of character pointers "argv" which stores the actual command line arguments.