1.
#include<stdio.h>
void main()
{
struct emp
{
char name[20];
int age;
float sal;
};
struct emp e={"Tiger"};
printf("\n %d %f",e.age,e.sal);
}
Correct Answer
A. 0 0.000000
Explanation
When an automatic structure is partially initialized, the remaining elements of the structure are initialized to 0.
2.
Which of the following set of statements is correct?
Correct Answer
C. Typedef long a;
extern a c;
Explanation
The correct answer is "typedef long a; extern a c;". This is because the first statement declares a typedef for a long integer called "a", and the second statement declares an extern variable of type "a" called "c". This is the correct syntax for declaring a typedef and an extern variable.
3.
By default a real number is treated as
Correct Answer
B. Double
Explanation
By default, a real number is treated as a double. The double data type is a 64-bit floating-point number that can represent a wider range of values with greater precision compared to the float data type. Therefore, when a real number is not explicitly declared with a specific data type, it is assumed to be a double.
4.
How many times the following program will print "Jamboree"?
#include<stdio.h>
void main()
{
printf("\n Jamboree");
main();
}
Correct Answer
D. Till the stact doesn't overflow
Explanation
The program will print "Jamboree" until the stack doesn't overflow. This is because the main function calls itself recursively without any condition to stop the recursion. As a result, the program will keep printing "Jamboree" indefinitely until the stack memory is exhausted and overflows.
5.
Is it true that too many recursive calls may result in stack overflow?
Correct Answer
A. True
Explanation
Too many recursive calls can result in a stack overflow because each recursive call adds a new stack frame to the call stack. If the recursion continues for a large number of times without a base case or proper termination condition, the call stack can become filled with a large number of stack frames, eventually exceeding the stack's capacity. This leads to a stack overflow error, causing the program to terminate abruptly.
6.
Predict the output of the following program
#include<stdio.h>
#define SQR(x) (x*x)
void main()
{
int a,b=3;
a=SQR(b+2);
printf("\n %d",a);
}
Correct Answer
B. 11
Explanation
Because,on preprocessing the expression becomes a=(3+2*3+2)
7.
Predict the output of the following program
#include<stdio.h>
void main()
{
static char *s[ ]={"black","white","pink","violet"};
char **ptr[ ]={s+3,s+2,s+1,s}, ***p;
p=ptr;
++p;
printf("%s", **p+1);
}
Correct Answer
A. Ink
Explanation
The program declares an array of strings named "s" and an array of pointers to pointers to char named "ptr". The array "s" contains the strings "black", "white", "pink", and "violet". The array "ptr" is assigned the addresses of the elements in "s" in reverse order. The pointer "p" is assigned the address of the first element in "ptr". The statement "++p" increments the pointer "p" to point to the next element in "ptr", which is the address of the string "pink". The statement "printf("%s", **p+1)" prints the string starting from the second character of "pink", which is "ink".
8.
Predict the output of the following program
#include<stdio.h>
#include<string.h>
void main()
{
char str[ ]="sales\0\man\0";
printf("%s",str);
}
Correct Answer
B. Sales
Explanation
The program declares a character array "str" and assigns it the value "sales\man\0". The printf statement then prints the value of "str". Since there are no formatting specifiers in the printf statement, it will simply print the string as it is. Therefore, the output of the program will be "sales".
9.
The library function used to reverse the string is
Correct Answer
B. Strrev( )
Explanation
The correct answer is "strrev( )". This is because the "strrev( )" function is a library function that is commonly used to reverse a string. It takes a string as input and returns the reversed string as output.
10.
Malloc( ) allocates memory from the heap and not from the stack
Correct Answer
A. True
Explanation
The malloc() function in C is used to allocate memory dynamically from the heap. The heap is a region of memory that is used for dynamic memory allocation. On the other hand, the stack is a region of memory used for storing local variables and function calls. When memory is allocated using malloc(), it is not allocated on the stack but rather on the heap. Therefore, the statement that malloc() allocates memory from the heap and not from the stack is true.