#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") )

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

1. C99 standard guarantees uniqueness of __________ characters for internal names.

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

8. Which of the following is not a valid C variable name?


a) int number; b) float rate; c) int variable_count; d) int $main;

9. Which of the following is true for variable names in C?


a) They can contain alphanumeric characters as well as special characters
b) It is not an error to declare a variable to be one of the keywords(like goto, static)
c) Variable names cannot start with a digit
d) Variable can be of any length

10. What will be the output of the following C code?

#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");
}

a) The compiler will flag an error


b) The program will compile and print the output 5
c) The program will compile and print the ASCII value of 5
d) The program will compile and print FAIL for 5 times

Atanu Bhandary Page 1


11. The format identifier ‘%i’ is also used for _____ data type.
a) char b) int c) float d) double

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

13. Which of the following is a User-defined data type?


a) typedef int Boolean; b) typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;
c) struct {char name[10], int age}; d) all of the mentioned

14. What is the size of an int data type?


a) 4 Bytes b) 8 Bytes c) 2 Bytes d)Depends on the system/compiler

15. What will be the output of the following C code?


#include <stdio.h>
int main()
{
signed char chr;
chr = 128;
printf("%d\n", chr);
return 0;
}

a) 128 b) -128 c) Depends on the compiler d) None of the mentioned

16. What will be the output of the following C code?

#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;
}

a) a b) Infinite loop c) Depends on what fgetc returns d) Depends on the compiler

17. What is short int in C programming?


a) The basic data type of C b) Qualifier
c) Short is the qualifier and int is the basic data type d) All of the mentioned

18. What will be the output of the following C code?

#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

19. What will be the output of the following C code?

#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

20. What will be the output of the following C code?

#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

21. What will be the output of the following C code?

#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

22. What will be the output of the following C code?

#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()
{

Atanu Bhandary Page 5


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;
}
1. }
a) Compile time error b) 1 c) 2 d) Varies

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

33. What will be the output of the following C code?

#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

34. What will be the output of the following C code?

Atanu Bhandary Page 7


#include <stdio.h>
int main()
{
int x = 97;
switch (x)
{
case 'a':
printf("yes ");
break;
case 97:
printf("no\n");
break;
}
}
a) yes b) yes no c) Duplicate case value error d) Character case value error

35. What will be the output of the following C code?

#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

36. What will be the output of the following C code?

#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

37. What will be the output of the following C code?

#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

38. What will be the output of the following C code?

#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

39. Comment on the output of the following C code.

#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

40. What will be the output of the following C code?

#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

41. What will be the output of the following C code?

#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

42. What will be the output of the following C code?

#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

43. What will be the output of the following C code?

#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

44. What will be the output of the following C code?

#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

45. What will be the output of the following C code?

#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

46. What will be the output of the following C code?

#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

d) Depends on the compiler

47. What will be the output of the following C code?

#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

48. What will be the output of the following C code?

#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

49. What is an example of iteration in C?


a) for b) while c) do-while d) all of the mentioned

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

Atanu Bhandary Page 12

You might also like