#Include Int Main (Int A (5) (1, 2, 3, 4, 5) Int I For (I 0 I 5 I++) If ( (Char) A (I) '5') Printf ("%D/N", A (I) ) Else Printf ("FAIL/n") )
#Include Int Main (Int A (5) (1, 2, 3, 4, 5) Int I For (I 0 I 5 I++) If ( (Char) A (I) '5') Printf ("%D/N", A (I) ) Else Printf ("FAIL/n") )
#Include Int Main (Int A (5) (1, 2, 3, 4, 5) Int I For (I 0 I 5 I++) If ( (Char) A (I) '5') Printf ("%D/N", A (I) ) Else Printf ("FAIL/n") )
a) 31 b) 63 c) 12 d) 14
2. C99 standard guarantees uniqueness of ___________ characters for external names.
a) 31 b) 6 c) 12 d) 14
3. Which of the following is not a valid variable name declaration?
a) int __a3; b) int __3a; c) int __A3; d) None of the mentioned
4. Which of the following is not a valid variable name declaration?
a) int _a3; b) int a_3; c) int 3_a; d) int _3a
5. Why do variable names beginning with the underscore is not encouraged?
a) It is not standardized
b) To avoid conflicts since assemblers and loaders use such names
c) To avoid conflicts since library routines use such names
d) To avoid conflicts with environment variables of an operating system
6. All keywords in C are in ____________
a) LowerCase letters b) UpperCase letters
c) CamelCase letters d) None of the mentioned
7. Variable name resolution (number of significant characters for the uniqueness of variable) depends on
___________
a) Compiler and linker implementations
b) Assemblers and loaders implementations
c) C language
d) None of the mentioned
#include <stdio.h>
int main()
{
int a[5] = {1, 2, 3, 4, 5};
int i;
for (i = 0; i < 5; i++)
if ((char)a[i] == '5')
printf("%d\n", a[i]);
else
printf("FAIL\n");
}
12. Which data type is most suitable for storing a number 65000 in a 32-bit system?
a) signed short b) unsigned short c) long d) int
#include <stdio.h>
int main()
{
char c;
int i = 0;
FILE *file;
file = fopen("test.txt", "w+");
fprintf(file, "%c", 'a');
fprintf(file, "%c", -1);
fprintf(file, "%c", 'b');
fclose(file);
file = fopen("test.txt", "r");
while ((c = fgetc(file)) != -1)
printf("%c", c);
return 0;
}
#include <stdio.h>
void main()
{
int x = 5;
Atanu Bhandary Page 2
if (x < 1)
printf("hello");
if (x == 5)
printf("hi");
else
printf("no");
}
a) hi b) hello c) no d) error
#include <stdio.h>
int x;
void main()
{
if (x)
printf("hi");
else
printf("how are u");
}
a) hi b) how are you c) compile time error d) error
#include <stdio.h>
void main()
{
int x = 5;
if (true);
printf("hello");
}
a) It will display hello b) It will throw an error
c) Nothing will be displayed d) Compiler dependent
#include <stdio.h>
void main()
{
int x = 0;
if (x == 0)
printf("hi");
else
printf("how are u");
printf("hello");
}
a) hi b) how are you c) hello d) hihello
#include <stdio.h>
void main()
{
int x = 5;
if (x < 1);
printf("Hello");
Atanu Bhandary Page 3
}
a) Nothing b) Run time error c) Hello d) Varies
23. What will be the output of the following C code? (Assuming that we have entered the value 1 in the
standard input)
#include <stdio.h>
void main()
{
double ch;
printf("enter a value between 1 to 2:");
scanf("%lf", &ch);
switch (ch)
{
case 1:
printf("1");
break;
case 2:
printf("2");
break;
}
}
a) Compile time error b) 1 c) 2 d) Varies
24. What will be the output of the following C code? (Assuming that we have entered the value 1 in the
standard input)
#include <stdio.h>
void main()
{
char *ch;
printf("enter a value between 1 to 3:");
scanf("%s", ch);
switch (ch)
{
case "1":
printf("1");
break;
case "2":
printf("2");
break;
}
}
a) 1 b) 2 c) Compile time error d) No Compile time error
25. What will be the output of the following C code? (Assuming that we have entered the value 1 in the
standard input)
#include <stdio.h>
void main()
{
int ch;
printf("enter a value between 1 to 2:");
scanf("%d", &ch);
switch (ch)
{
Atanu Bhandary Page 4
case 1:
printf("1\n");
default:
printf("2\n");
}
}
a) 1 b) 2 c) 1 2 d) Run time error
26. What will be the output of the following C code? (Assuming that we have entered the value 2 in the
standard input)
#include <stdio.h>
void main()
{
int ch;
printf("enter a value between 1 to 2:");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("1\n");
break;
printf("Hi");
default:
printf("2\n");
}
1. }
a) 1 b) Hi 2 c) Run time error d) 2
27. What will be the output of the following C code? (Assuming that we have entered the value 1 in the
standard input)
#include <stdio.h>
void main()
{
int ch;
printf("enter a value between 1 to 2:");
scanf("%d", &ch);
switch (ch, ch + 1)
{
case 1:
printf("1\n");
break;
case 2:
printf("2");
break;
}
}
a) 1 b) 2 c) 3 d) Run time error
28. What will be the output of the following C code? (Assuming that we have entered the value 1 in the
standard input)
#include <stdio.h>
void main()
{
29. What will be the output of the following C code? (Assuming that we have entered the value 1 in the
standard input)
#include <stdio.h>
void main()
{
char *ch;
printf("enter a value between 1 to 3:");
scanf("%s", ch);
switch (ch)
{
case "1":
printf("1");
break;
case "2":
printf("2");
break;
}
}
a) 1 b) Compile time error c) 2 d) Run time error
30. What will be the output of the following C code? (Assuming that we have entered the value 1 in the
standard input)
#include <stdio.h>
void main()
{
int ch;
printf("enter a value between 1 to 2:");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("1\n");
default:
printf("2\n");
}
}
a) 1 b) 2 c) 1 2 d) Run time error
31. What will be the output of the following C code? (Assuming that we have entered the value 2 in the
standard input)
Atanu Bhandary Page 6
#include <stdio.h>
void main()
{
int ch;
printf("enter a value between 1 to 2:");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("1\n");
break;
printf("hi");
default:
printf("2\n");
}
}
a) 1 b) hi 2 c) Run time error d) 2
32. What will be the output of the following C code? (Assuming that we have entered the value 1 in the
standard input)
#include <stdio.h>
void main()
{
int ch;
printf("enter a value between 1 to 2:");
scanf("%d", &ch);
switch (ch, ch + 1)
{
case 1:
printf("1\n");
break;
case 2:
printf("2");
break;
}
}
a) 1 b) 2 c) 3 d) Run time error
#include <stdio.h>
int main()
{
int a = 1, b = 1;
switch (a)
{
case a*b:
printf("yes ");
case a-b:
printf("no\n");
break;
}
}
a) yes b) no c) Compile time error d) yes no
#include <stdio.h>
int main()
{
float f = 1;
switch (f)
{
case 1.0:
printf("yes\n");
break;
default:
printf("default\n");
}
}
a) yes b) yes default c) Undefined behaviour d) Compile time error
#include <stdio.h>
const int a = 1, b = 2;
int main()
{
int x = 1;
switch (x)
{
case a:
printf("yes ");
case b:
printf("no\n");
break;
}
}
a) yes no b) yes c) no d) Compile time error
#include <stdio.h>
#define max(a) a
int main()
{
Atanu Bhandary Page 8
int x = 1;
switch (x)
{
case max(2):
printf("yes\n");
case max(1):
printf("no\n");
break;
}
1. }
a) yes no b) yes c) no d) Compile time error
#include <stdio.h>
int main()
{
switch (printf("Do"))
{
case 1:
printf("First\n");
break;
case 2:
printf("Second\n");
break;
default:
printf("Default\n");
break;
}
}
a) Do b) DoFirst c) DoSecond d) DoDefault
#include <stdio.h>
int main()
{
int a = 1;
switch (a)
case 1:
printf("%d", a);
case 2:
printf("%d", a);
case 3:
printf("%d", a);
default:
printf("%d", a);
}
a) output is 1111 b) output is 1
c) Compile time error, no break statements d) Compile time error, case label outside switch
statement
#include <stdio.h>
void main()
{
Atanu Bhandary Page 9
double k = 0;
for (k = 0.0; k < 3.0; k++);
printf("%lf", k);
1. }
a) 2.000000 b) 4.000000 c) 3.000000 d) Run time error
#include <stdio.h>
void main()
{
int k;
for (k = -3; k < -5; k++)
printf("Hello");
}
a) Hello b) Infinite hello c) Run time error d) Nothing
#include <stdio.h>
int main()
{
int i = 0;
for (; ; ;)
printf("In for loop\n");
printf("After loop\n");
}
a) Compile time error b) Infinite loop c) After loop d) Undefined
behaviour
#include <stdio.h>
int main()
{
int i = 0;
for (i++; i == 1; i = 2)
printf("In for loop ");
printf("After loop\n");
}
a) In for loop after loop b) After loop c) Compile time error d) Undefined behaviour
#include <stdio.h>
int main()
{
int i = 0;
for (foo(); i == 1; i = 2)
printf("In for loop\n");
printf("After loop\n");
}
int foo()
{
return 1;
}
Atanu Bhandary Page 10
a) After loop b) In for loop after loop c) Compile time error d) Infinite loop
#include <stdio.h>
int main()
{
int *p = NULL;
for (foo(); p; p = 0)
printf("In for loop\n");
printf("After loop\n");
}
a) In for loop after loop b) Compile time error c) Infinite loop
d) Depends on the value of NULL
#include <stdio.h>
int main()
{
for (int i = 0;i < 1; i++)
printf("In for loop\n");
}
a) Compile time error b) In for loop c) Depends on the standard compiler implements
#include <stdio.h>
void main()
{
char *str = "";
do
{
printf("hello");
} while (str);
}
a) Nothing b) Run time error c) Varies d) Hello is printed infinite times
#include <stdio.h>
void main()
{
int i = 0;
while (i < 10)
{
i++;
printf("hi\n");
while (i < 8)
{
i++;
printf("hello\n");
}
}
Atanu Bhandary Page 11
}
a) Hi is printed 8 times, hello 7 times and then hi 2 times
b) Hi is printed 10 times, hello 7 times
c) Hi is printed once, hello 7 times
d) Hi is printed once, hello 7 times and then hi 2 times
4. How many times while loop condition is tested in the following C code snippets, if i is initialized to 0 in
both the cases?
while (i < n)
i++;
————-
do
i++;
while (i <= n);
a) n, n b) n, n+1 c) n+1, n d) n+1, n+1