main() is called every time. Hence its an infinite loop.
Q. No. :
2
Question :
What will happen when the program below is compiled and executed?
#include <stdio.h>
int i;
void increment( int i )
{
i++;
}
int main()
{
for( i = 0; i < 10; increment( i ) )
{
}
printf("i=%d
", i);
return 0;
}
A :
It will not compile.
B :
It will print out: i=10
C :
It will print out: i=11
D :
It will loop indefinitely
Answer: D
Q. No. :
3
Question :
What will the output?
int i = 4;
switch (i)
{
default:
;
case 3:
i += 5;
if ( i == 8)
{
i++;
if (i == 9) break;
i *= 2;
}
i -= 4;
break;
case 8:
i += 5;
break;
}
printf("i = %d
", i);
(2<0) is false hence four is printed and printf returns the no. of characters printed ie 4 to x.
Hence four4
Q. No. :
5
Question :
What does the "auto" specifier do?
A :
It automatically initializes a variable to 0;
B :
It indicates that a variable's memory will automatically be preserved.
C :
It automatically increments the variable when used.
D :
It automatically initializes a variable to NULL.
Answer: B
Q. No. :
6
Question :
What will be the output of the program?
#include< stdio.h >
int sumdig(int);
int main()
{
int a, b;
a = sumdig(123);
b = sumdig(123);
printf("%d, %d
", a, b);
return 0;
}
int sumdig(int n)
{
int s, d;
if(n!=0)
{
d = n%10;
n = n/10;
s = d+sumdig(n);
}
else
return 0;
return s;
}
A :
4,4
B :
3,3
C :
6,6
D :
12,12
Answer: C
Q. No. :
7
Question :
What will print when the sample code below is executed?
While calling the function myFunc address of array is passed and it is incremented by 3. Hence Now the address is pointing to L and print onwards ie LLO
Q. No. :
8
Question :
The sample code above releases memory from a linked list. Which of the choices below accurately describes how it will work?
struct node *nPtr, *sPtr; /* pointers for a linked list. */
for (nPtr=sPtr; nPtr; nPtr=nPtr->next)
{
free(nPtr);
}
A :
It will work correctly since the for loop covers the entire list.
B :
It may fail since each node "nPtr" is freed before its next address can be accessed.
C :
In the for loop, the assignment "nPtr=nPtr->next" should be changed to "nPtr=nPtr.next".
int a [8] = { 0, 1, 2, 3 };
The definition of a above explicitly initializes its first four elements. Which one of the following describes how the compiler treats the remaining four elements?
A :
Standard C defines this particular behavior as implementation-dependent. The compiler writer has the freedom to decide how the remaining elements will be handled.
B :
The remaining elements are initialized to zero(0)
C :
It is illegal to initialize only a portion of the array. Either the entire array must be initialized, or no part of it may be initialized
D :
As with an enum, the compiler assigns values to the remaining elements by counting up from the last explicitly initialized element. The final four elements will acquire the values 4, 5, 6, and 7, respectively.
The macro function SQR(x)(x*x) calculate the square of the given number 'x'. (Eg: 102) Step 1: int a, b=3; Here the variable a, b are declared as an integer type and the variable b is initialized to 3. Step 2: a = SQR(b+2); becomes, => a = b+2 * b+2; Here SQR(x) is replaced by macro to x*x . => a = 3+2 * 3+2; => a = 3 + 6 + 2; => a = 11; Step 3: printf("%d
", a); It prints the value of variable 'a'. Hence the output of the program is 11
Q. No. :
23
Question :
What number will z in the sample code below contain?
Step 1: x=y=z=1; here the variables x ,y, z are initialized to value '1'.
Step 2: z = ++x || ++y && ++z; becomes z = ( (++x) || (++y && ++z) ). Here ++x becomes 2. So there is no need to check the other side because ||(Logical OR) condition is satisfied.(z = (2 || ++y && ++z)). There is no need to process ++y && ++z. Hence it returns '1'. So the value of variable z is '1'
Step 3: printf("x=%d, y=%d, z=%d
", x, y, z); It prints "x=2, y=1, z=1". here x is increemented in previous step. y and z are not increemented.
Q. No. :
25
Question :
Assuming a short is two bytes long, what will be printed by the above code?
The struct emp is mentioned in the prototype of the function modify() before declaring the structure.To solve this problem declare struct emp before the modify() prototype.