NEW
Font size
WorksheetsCan you C?
Total questions: 5
Worksheet time: 2mins
What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *str = "";
do
{
printf("hello");
} while (str);
}
Nothing
Run time Error
Hello is printed infinite times
Hello is printed one time
How many times while loop condition is tested in the following C code snippets, if i is initialized to 0 in both the cases?
1.
while (i < n)
i++;
2.
do
i++;
while (i <= n);
n, n
n, n+1
n+1, n
n+1, n+1
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int i = 0;
while (i = 0)
printf("True\n");
printf("False\n");
}
True (infinite time)
True (1 time) False
False
Compiler dependent
#include <stdio.h>
void main()
{
int a = 5, b = -7, c = 0, d;
d = ++a && ++b || ++c;
printf("\n%d%d%d%d", a, b, c, d);
}
6 -6 0 0
6 -5 0 1
-6 -6 0 1
6 -6 0 1
#include <stdio.h>
int main()
{
int x = -2;
x = x >> 1;
printf("%d\n", x);
}
1
-1
2^31 – 1 considering int to be 4 bytes
Either -1 or 1
