C Language Interview Questions Test 9
This Test will cover complete C with very important questions, starting off from basics to advanced level.
Q. If a variable can take only integral values from 0 to n
, where n is a constant integer, then the variable can be representated as a bit-field
whose width is the integral part of(the log in the answers are to the base 2)
Q. The statement printf("%d", 10?0?5:11:12);
prints __________?
Q. The statement printf("%d", sizeof(""));
prints __________?
Q. If p
is a pointer to an integer and t
is a pointer to a character then sizeof(p)
will be?
Q. Consider the declaration, Choose the correct remark(s).
char street[10] = "abcdefghi";
Q. Consider the following program fragment. The output will be?
int d = 0;
int i, j, k;
for(i=1; i < 31; ++i)
for(j=1; j < 31; ++j)
for(k=1; k < 31; ++k)
if(((i+j+k)%3) == 0)
d = d+1;
printf("%d", d);
Q. The number of additions performed by the above program fragment is?
Q. Consider the following C function. What is the value of f(5)
?
int f(int n)
{
static int r=0;
if(n <= 0)
return 1;
if(n > 3)
{
r = n;
return f(n-2) +2;
}
return f(n-1) + r;
}
Q. Which combination of the integer variables x, y, z
makes the variable a
get the value 4 in the following expression?
a = (x>y) ? ((x>z) ? x:z) : ((y>z) ? y:z)
Q. What is the value printed by the following C program?
#include<stdio.h>
int f(nt *a, int n)
{
if(n <= 0)
return 0;
else if(*a%2 == 0)
return *a + f(a+1, n+1);
else
return *a - f(a+1, n-1);
}
int main()
{
int a[] = {12, 7, 13, 4, 11, 6};
printf("%d", f(a,6));
return 0;
}
Q. What does the following fragment of C program prints?
char c[] = "GATE2017";
char *p = c;
printf("%s", p + p[3] - p[1]);
Q. What does the following program prints?
#include<stdio.h>
void f(int *p, int *q)
{
p = q;
*p = 2;
}
int i = 0, j = 1;
int main()
{
f(&i, &j);
printf("%d %d\n", i, j);
return 0;
}
Q. Consider the following C program segment where CellNode
represents a node in a binary tree. The value returned by GetValue
when a pointer to the root of a binary tree
is passed as its argument is?
struct CellNode
{
struct CellNode *leftChild;
int element;
struct CellNode *rightChild;
};
int GetValue(struct CellNode *ptr)
{
int value=0;
if(ptr !=NULL)
{
if((ptr->leftChild == NULL) && (ptr->rightChild == NULL))
{
value=1;
}
else
{
value = value + GetValue(ptr->leftChild) + GetValue(ptr->rightChild);
}
return (value);
}
Q. Consider the following segment of C language code. The number of comparisons made in the execution of the loop for any n > 0
is?
int j, n;
j = 1;
while(j <= n)
{
j = j*2;
}
Q. The statement printf("%d", (a++));
prints?