Ugctutorials.weebly.com



1. Variable names beginning with underscore is not encouraged. Why?

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

Answer:c

2. Variable name resolving (number of significant characters for uniqueness of variable) depends on

a) Compiler and linker implementations b) Assemblers and loaders implementations

c) C language d) None

Answer:a Explanation:It depends on the standard to which compiler and linkers are adhering to.

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

a) int number; b) float rate;

c) int variable_count; d) int $main;

Answer:d

Explanation:Since only underscore and no other special character is allowed in a variable name, it results in an error.

4. 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

Answer:c Explanation:According to the syntax for C variable name, it cannot start with a digit.

5. Which is valid C expression?

a) int my_num = 100,000; b) int my_num = 100000;

c) int my num = 1000; d) int $my_num = 10000;

Answer:b Explanation:space, comma and $ cannot be used in a variable name.

6. What is the output of this C code?

#include

int main()

{

printf("Hello World! %d \n", x);

return 0;

}

a) Hello World! x; b) Hello World! followed by a junk value

c) Compile time error d) Hello World!

Answer:c

Explanation:It results in an error since x is used without declaring the variable x.

Output:$ cc pgm1.c

pgm1.c: In function ‘main’:

pgm1.c:4: error: ‘x’ undeclared (first use in this function)

pgm1.c:4: error: (Each undeclared identifier is reported only once

pgm1.c:4: error: for each function it appears in.)

7. What is the output of this C code?

#include

int main()

{

int y = 10000;

int y = 34;

printf("Hello World! %d\n", y);

return 0;

}

a) Compile time error b) Hello World! 34

c) Hello World! 1000 d) Hello World! followed by a junk value

Answer:a

Explanation:Since y is already defined, redefining it results in an error.

Output: $ cc pgm2.c

pgm2.c: In function ‘main’:

pgm2.c:5: error: redefinition of ‘y’

pgm2.c:4: note: previous definition of ‘y’ was here

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

a) float PI = 3.14; b) double PI = 3.14;

c) int PI = 3.14; d) #define PI 3.14

Answer:d Explanation:#define PI 3.14 is a macro preprocessor, it is a textual substitution.

9. What will happen if the below program is executed?

#include

int main()

{

int main = 3;

printf("%d", main);

return 0;

}

a) It will cause a compile-time error b) It will cause a run-time error

c) It will run without any error and prints 3 d) It will experience infinite looping

Answer:c

Explanation:A C program can have same function name and same variable name.

$ cc pgm3.c $ a.out3

10. What is the problem in following variable declaration?

float 3Bedroom-Hall-Kitchen?;

a) The variable name begins with an integer b) The special character ‘-’

c) The special character ‘?’ d) All of the mentioned

Answer:d

Explanation:A variable name cannot start with an integer, along with that the C compiler

interprets the ‘-’ and ‘?’ as a minus operator and a question mark operator respectively.

11. Comment on the output of this C code?

#include

int main()

{

int ThisIsVariableName = 12;

int ThisIsVariablename = 14;

printf("%d", ThisIsVariablename);

return 0;

}

a) The program will print 12

b) The program will print 14

c) The program will have a runtime error

d) The program will cause a compile-time error due to redeclaration

Answer:b

Explanation:Variable names ThisIsVariablename and ThisIsVariableName are both distinct as C is case sensitive.

Output:

$ cc pgm4.c

$ a.out 14

12. Which of the following cannot be a variable name in C?

a) volatile b) true

c) friend d) export

Answer: a Explanation:volatile is C keyword.

13. Comment on the output of this C code?

#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) The compiler will flag an error

b) Program will compile and print the output 5

c) Program will compile and print the ASCII value of 5

d) Program will compile and print FAIL for 5 times

Answer:d

Explanation:The ASCII value of 5 is 53, the char type-casted integral value 5 is 5 only.

Output:$ cc pgm1.c $ a.out

FAILED

FAILED

FAILED

14. The format identifier ‘%i’ is also used for _____ data type?

a) char b) int

c) float d) double

Answer:b

Explanation:Both %d and %i can be used as a format identifier for int data type.

15. Which data type is most suitable for storing a number 65000 in a 32-bit system?

a) short b) int

c) long d) double

Answer:a

Explanation:65000 comes in the range of short (16-bit) which occupies the least memory.

16. 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

Answer:d

Explanation:typedef and struct are used to define user-defined data types.

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

a) 4 Bytes b) 8 Bytes

c) Depends on the system/compiler d) Cannot be determined

Answer:c

Explanation:The size of the data types depend on the system.

18. What is the output of this C code?

#include

int main()

{

char chr;

chr = 128;

printf("%d\n", chr);

return 0;

}

a) 128 b) -128

c) Depends on the compiler d) None of the mentioned

Answer:b

Explanation:signed char will be a negative number.

Output:$ cc pgm2.c

$ a.out

-128

19. Comment on the output of this C code?

#include

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

Answer:a.

Output: $ cc pgm3.c $ a.out a

20. What is short int in C programming?

a) Basic datatype of C b) Qualifier

c) short is the qualifier and int is the basic datatype d) All of the mentioned

Answer:c

21. Comment on the output of this C code?

#include

int main()

{

float f1 = 0.1;

if (f1 == 0.1)

printf("equal\n");

else

printf("not equal\n");

}

a) equal b) not equal

c) Output depends on compiler d) None of the mentioned

Answer:b

Explanation:0.1 by default is of type double which has different representation than float resulting in inequality even after conversion.

Output:

$ cc pgm4.c

$ a.out

not equal

22. Comment on the output of this C code?

#include

int main()

{

float f1 = 0.1;

if (f1 == 0.1f)

printf("equal\n");

else

printf("not equal\n");

}

a) equal b) not equal

c) Output depends on compiler d) None of the mentioned

Answer:a Explanation:0.1f results in 0.1 to be stored in floating point representations.

Output:

$ cc pgm5.c

$ a.out

equal

23. What is the output of this C code (on a 32-bit machine)?

#include

int main()

{

int x = 10000;

double y = 56;

int *p = &x;

double *q = &y;

printf("p and q are %d and %d", sizeof(p), sizeof(q));

return 0;

}

a) p and q are 4 and 4 b) p and q are 4 and 8

c) Compiler error d) p and q are 2 and 8

Answer:a

Explanation:Size of any type of pointer is 4 on a 32-bit machine.

Output: $ cc pgm6.c

$ a.out

p and q are 4 and 4

24. Which is correct with respect to size of the datatypes?

a) char > int > float b) int > char > float

c) char < int < double d) double > char > int

Answer:c

Explanation:char has lesser bytes than int and int has lesser bytes than double in any system

25. What is the output of the following C code(on a 64 bit machine)?

#include

union Sti

{

int nu;

char m;

};

int main()

{

union Sti s;

printf("%d", sizeof(s));

return 0;

}

a) 8 b) 5

c) 9 d) 4

Answer:d

Explanation:Since the size of a union is the size of its maximum datatype, here int is the largest hence 4.

Output:

$ cc pgm7.c

$ a.out

4

26. What is the output of this C code?

#include

int main()

{

float x = 'a';

printf("%f", x);

return 0;

}

a) a b) run time error

c) a.0000000 d) 97.000000

Answer:d

Explanation:Since the ASCII value of a is 97, the same is assigned to the float variable and printed.

Output:

$ cc pgm8.c

$ a.out

97.000000

27. Which of the datatypes have size that is variable?

a) int b) struct

c) float d) double

Answer:b Explanation:Since the size of the structure depends on its fields, it has a variable size.

28. What is the output of this C code?

#include

void foo(const int *);

int main()

{

const int i = 10;

printf("%d ", i);

foo(&i);

printf("%d", i);

 

}

void foo(const int *i)

{

*i = 20;

}

a) Compile time error b) 10 20

c) Undefined value d) 10

Answer:a

Explanation:Cannot change a const type value.

Output:

$ cc pgm1.c

pgm1.c: In function ‘foo’:

pgm1.c:13: error: assignment of read-only location ‘*i’

29. Comment on the output of this C code?

#include

int main()

{

const int i = 10;

int *ptr = &i;

*ptr = 20;

printf("%d\n", i);

return 0;

}

a) Compile time error b) Compile time warning and printf displays 20

c) Undefined behavior d) 10

Answer:b

Explanation:Changing const variable through non-constant pointers invokes compiler warning

Output:

$ cc pgm2.c

pgm2.c: In function ‘main’:

pgm2.c:5: warning: initialization discards qualifiers from pointer target type

$ a.out

20

30. What is the output of this C code?

#include

int main()

{

j = 10;

printf("%d\n", j++);

return 0;

}

a) 10 b) 11

c) Compile time error d) 0

Answer:c Explanation:Variable j is not defined.

Output:$ cc pgm3.c

pgm3.c: In function ‘main’:

pgm3.c:4: error: ‘j’ undeclared (first use in this function)

pgm3.c:4: error: (Each undeclared identifier is reported only once

pgm3.c:4: error: for each function it appears in.)

31. Does this compile without error?

#include

int main()

{

for (int k = 0; k < 10; k++);

return 0;

}

a) Yes b) No

c) Depends on the C standard implemented by compilers d) None of the mentioned

Answer:c Explanation:Compilers implementing C90 does not allow this but compilers implementing C99 allow it.

Output: $ cc pgm4.c

pgm4.c: In function ‘main’:

pgm4.c:4: error: ‘for’ loop initial declarations are only allowed in C99 mode

pgm4.c:4: note: use option -std=c99 or -std=gnu99 to compile your code

32. Does this compile without error?

#include

int main()

{

int k;

{

int k;

for (k = 0; k < 10; k++);

}

}

a) Yes b) No

c) Depends on the compiler d) Depends on the C standard implemented by compilers

Answer:a Explanation:There can be blocks inside block and within blocks variables have only block scope.

Output:

$ cc pgm5.c

33. Which of the following declaration is not supported by C?

a) String str; b) char *str;

c) float str = 3e2; d) Both (a) and (c)

Answer:a Explanation:It is legal in Java, not in C.

34.

#include

int main()

{

char *var = "Advanced Training in C by ";

}

Which of the following format identifier can never be used for the variable var?

a) %f b) %d

c) %c d) %s

Answer:a

Explanation:%c can be used to print the indexed position. %d can still be used to display its ASCII value. %s is recommended.

%f cannot be used.

35. What is the output of this C code?

#include

int main()

{

int i = -3;

int k = i % 2;

printf("%d\n", k);

}

a) Compile time error b) -1

c) 1 d) Implementation defined

Answer:b

36. What is the output of this C code?

#include

int main()

{

int i = 3;

int l = i / -2;

int k = i % -2;

printf("%d %d\n", l, k);

return 0;

}

a) Compile time error b) -1 1

c) 1 -1 d) Implementation defined

Answer:b

37. What is the output of this C code?

#include

int main()

{

int i = 5;

i = i / 3;

printf("%d\n", i);

return 0;

}

a) Implementation defined b) 1

c) 3 d) Compile time error

Answer:b

38. What is the output of this C code?

#include

int main()

{

int i = -5;

i = i / 3;

printf("%d\n", i);

return 0;

}

a) Implementation defined b) -1

c) -3 d) Compile time error

Answer:b

35. What is the value of x in this C code?

#include

void main()

{

int x = 5 * 9 / 3 + 9;

}

a) 3.75 b) Depends on compiler

c) 24 d) 3

Answer:c

40. What is the output of this C code?

#include

void main()

{

int x = 5.3 % 2;

printf("Value of x is %d", x);

}

a) Value of x is 2.3 b) Value of x is 1

c) Value of x is 0.3 d) Compile time error

Answer:d

41. What is the output of this C code?

#include

void main()

{

int y = 3;

int x = 5 % 2 * 3 / 2;

printf("Value of x is %d", x);

}

a) Value of x is 1 b) Value of x is 2

c) Value of x is 3 d) Compile time error

Answer:a

42. What is the output of this C code?

#include

void main()

{

int a = 3;

int b = ++a + a++ + --a;

printf("Value of b is %d", b);

}

a) Value of x is 12 b) Value of x is 13

c) Value of x is 10 d) Undefined behavior

Answer:d

43. The precedence of arithmetic operators is (from highest to lowest)

a) %, *, /, +, - b) %, +, /, *, -

c) +, -, %, *, / d) %, +, -, *, /

Answer:a

44. Which of the following is not an arithmetic operation?

a) a *= 10; b) a /= 10;

c) a != 10; d) a %= 10;

Answer:c

45. Which of the following data type will throw an error on modulus operation(%)?

a) char b) short

c) int d) float

Answer:d

46. Which among the following are the fundamental arithmetic operators, ie, performing the desired operation can be done using that operator only?

a) +, - b) +, -, %

c) +, -, *, / d) +, -, *, /, %

Answer:a

47. What is the output of this C code?

#include

int main()

{

int a = 10;

double b = 5.6;

int c;

c = a + b;

printf("%d", c);

}

a) 15 b) 16

c) 15.6 d) 10

Answer:a

7. What is the output of this C code?

#include

int main()

{

int a = 10, b = 5, c = 5;

int d;

d = a == (b + c);

printf("%d", d);

}

a) Syntax error b) 1

c) 10 d) 5

Answer: b

48. function tolower(c) defined in library works for

a) Ascii character set b) Unicode character set

c) Ascii and utf-8 but not EBSIDIC character set d) Any character set

Answer:d

49. What is the output of the below code considering size of short int is 2, char is 1 and int is 4 bytes?

#include

int main()

{

short int i = 20;

char c = 97;

printf("%d, %d, %d\n", sizeof(i), sizeof(c), sizeof(c + i));

return 0;

}

a) 2, 1, 2 b) 2, 1, 1

c) 2, 1, 4 d) 2, 2, 8

Answer:c

50. Which type conversion is NOT accepted?

a) From char to int b) From float to char pointer

c) From negative int to char d) From double to char

Answer:b

Explanation:Conversion of a float to pointer type is not allowed.

51. What will be the data type of the result of the following operation?

(float)a * (int)b / (long)c * (double)d

a) int b) long

c) float d) double

Answer:d

52. Which of the following type-casting have chances for wrap around?

a) From int to float b) From int to char

c) From char to short d) From char to int

53. Which of the following typecasting is accepted by C?

a) Widening conversions b) Narrowing conversions

c) Both d) None of the mentioned

Answer:c

54. When do you need to use type-conversions?

a) The value to be stored is beyond the max limit

b) The value to be stored is in a form not supported by that data type

c) To reduce the memory in use, relevant to the value

d) All of the mentioned

Answer: d

55. What is the output of this C code?

#include

void main()

{

int x = 0;

if (x = 0)

printf("Its zero\n");

else

printf("Its not zero\n");

}

a) Its not zero b) Its zero

c) Run time error d) None

Answer:a

56. What is the output of this C code?

#include

void main()

{

int k = 8;

int x = 0 == 1 && k++;

printf("%d%d\n", x, k);

}

a) 0 9 b) 0 8

c) 1 8 d) 1 9

Answer:b

57. What is the output of this C code?

#include

void main()

{

char a = 'a';

int x = (a % 10)++;

printf("%d\n", x);

}

a) 6 b) Junk value

c) Compile time error d) 7

Answer:c

58. What is the output of this C code?

#include

void main()

{

1 < 2 ? return 1: return 2;

}

a) returns 1 b) returns 2

c) Varies d) Compile time error

Answer:d

59. What is the output of this C code?

#include

void main()

{

unsigned int x = -5;

printf("%d", x);

}

a) Run time error b) Aries

c) -5 d) 5

Answer:c

60. What is the output of this C code?

#include

int main()

{

int x = 2, y = 1;

x *= x + y;

printf("%d\n", x);

return 0;

}

a) 5 b) 6

c) Undefined behavior d) Compile time error

Answer:d

61. What is the output of this C code?

#include

int main()

{

int x = 2, y = 2;

x /= x / y;

printf("%d\n", x);

return 0;

}

a) 2 b) 1

c) 0.5 d) Undefined behavior

Answer:a

62. What is the output of this C code?

#include

int main()

{

int x = 1, y = 0;

x &&= y;

printf("%d\n", x);

}

a) Compile time error b) 1

c) 0 d) Undefined behavior

Answer:a

63. What is the output of this C code?

#include

int main()

{

int c = 2 ^ 3;

printf("%d\n", c);

}

a) 1 b) 8

c) 9 d) 0

Answer: a

64. What is the output of this C code?

#include

int main()

{

unsigned int a = 10;

a = ~a;

printf("%d\n", a);

}

a) -9 b) -10

c) -11 d) 10

Answer:c

65. What is the output of this C code?

#include

int main()

{

if (7 & 8)

printf("Honesty");

if ((~7 & 0x000f) == 8)

printf("is the best policy\n");

}

a) Honesty is the best policy b) Honesty

c) is the best policy d) No output

Answer:c

66. What is the output of this C code?

#include

int main()

{

int a = 2;

if (a >> 1)

printf("%d\n", a);

}

a) 0 b) 1

c) 2 d) No Output.

Answer:c

67. Comment on the output of this C code?

#include

int main()

{

int i, n, a = 4;

scanf("%d", &n);

for (i = 0; i < n; i++)

a = a * 2;

}

a) Logical Shift left b) No output

c) Arithmetic Shift right d) bitwise exclusive OR

Answer:b

68. What is the output of this C code?

#include

void main()

{

int x = 97;

int y = sizeof(x++);

printf("x is %d", x);

}

a) x is 97 b) x is 98

c) x is 99 d) Run time error

Answer:a

69. What is the output of this C code?

#include

void main()

{

int x = 4, y, z;

y = --x;

z = x--;

printf("%d%d%d", x, y, z);

}

a) 3 2 3 b) 2 2 3

c) 3 2 2 d) 2 3 3

Answer:d

70. What is the output of this C code?

#include

void main()

{

int x = 4;

int *p = &x;

int *k = p++;

int r = p - k;

printf("%d", r);

}

a) 4 b) 8

c) 1 d) Run time error

Answer:c

71. The output of the code below is

#include

void main()

{

int x = 5;

if (x < 1)

printf("hello");

if (x == 5)

printf("hi");

else

printf("no");

}

a) hi b) hello

c) no d) None of the mentioned

Answer:a

72. The output of the code below is

#include

int x;

void main()

{

if (x)

printf("hi");

else

printf("how are u");

}

a) hi b) how are you

c) Compile time error d) None of the mentioned

Answer:b

73. Comment on the following code below

#include

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

Answer:b

74. The output of the code below is

#include

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

Answer:d

75. The output of the code below is

#include

void main()

{

int x = 5;

if (x < 1);

printf("Hello");

 

}

a) Nothing b) Run time error

c) Hello d) Varies

Answer:c

76. The output of the code below is(when 1 is entered)

#include

void main()

{

double ch;

printf("enter a value btw 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

Answer:a

77. The output of the code below is(When 1 is entered)

#include

void main()

{

char *ch;

printf("enter a value btw 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

Answer:c

78. When 1 is entered, The output of the code below is?

#include

void main()

{

int ch;

printf("enter a value btw 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

Answer:c

79. When 2 is entered, The output of the code below is?

#include

void main()

{

int ch;

printf("enter a value btw 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

Answer:d

80. When 1 is entered, The output of the code below is?

#include

void main()

{

int ch;

printf("enter a value btw 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

Answer:b

81. What is the output of this C code?

#include

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

Answer:d

82. What is the output of this C code?

#include

#define max(a) a

int main()

{

int x = 1;

switch (x)

{

case max(2):

printf("yes\n");

case max(1):

printf("no\n");

break;

}

}

a) yes no b) yes

c) no d) Compile time error

Answer:c

83. What is the output of this C code?

#include

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

Answer:c

84. Comment on the output of this C code?

#include

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) No error, output is 1111

b) No error, output is 1

c) Compile time error, no break statements

d) Compile time error, case label outside switch statement

Answer:d

85. Switch statement accepts.

a) int b) char

c) long d) All of the mentioned

Answer:d

86. Comment on the output of this C code?

#include

int main()

{

int a = 1;

switch (a)

{

case a:

printf("Case A ");

default:

printf("Default");

}

}

a) Output: Case A b) Output: Default

c) Output: Case A Default d) Compile time error

Answer:d

87. Comment on the output of this C code?

#include

switch (ch)

{

case 'a':

case 'A':

printf("true");

}

a) if (ch == ‘a’ && ch == ‘A’) printf(“true”); b) if (ch == ‘a’) if (ch == ‘a’) printf(“true”);

c) if (ch == ‘a’ || ch == ‘A’) printf(“true”); d) Both a and b

Answer:c

88. The following code ‘for(;;)’ represents an infinite loop. It can be terminated by.

a) break b) exit(0)

c) abort() d) All of the mentioned

Answer:a

89. The correct syntax for running two variable for loop simultaneously is.

a) for (i = 0; i < n; i++)

     for (j = 0; j < n; j += 5)

b) for (i = 0, j = 0;i < n, j < n; i++, j += 5)

c) for (i = 0; i < n;i++){}

    for (j = 0; j < n;j += 5){}

d) None of the mentioned

Answer:b

90. Which for loop has range of similar indexes of 'i' used in for (i = 0;i < n; i++)?

a) for (i = n; i>0; i–) b) for (i = n; i >= 0; i–)

c) for (i = n-1; i>0; i–) d) for (i = n-1; i>-1; i–)

Answer:d

91. Which of the following cannot be used as LHS of the expression in for (exp1;exp2; exp3) ?

a) Variable b) Function

c) typedef d) macros

Answer:d

96. What is the output of this C code?

#include

int main()

{

short i;

for (i = 1; i >= 0; i++)

printf("%d\n", i);

 

}

a) The control won’t fall into the for loop

b) Numbers will be displayed until the signed limit of short and throw a runtime error

c) Numbers will be displayed until the signed limit of short and program will successfully     terminate

d) This program will get into an infinite loop and keep printing numbers with no errors

Answer:c

97. What is the output of this C code?

#include

void main()

{

int k = 0;

for (k)

printf("Hello");

}

a) Compile time error b) hello

c) Nothing d) Varies

Answer:a

98. What is the output of this C code?

#include

void main()

{

int k = 0;

for (k < 3; k++)

printf("Hello");

}

a) Compile time error b) Hello is printed thrice

c) Nothing d) Varies

Answer:a

99. What is the output of this C code?

#include

void main()

{

double k = 0;

for (k = 0.0; k < 3.0; k++)

printf("Hello");

}

a) Run time error b) Hello is printed thrice

c) Hello is printed twice d) Hello is printed infinitely

Answer:b

100. What is the output of this C code?

#include

void main()

{

char *str = "";

do

{

printf("hello");

} while (str);

}

a) Nothing b) Run time error

c) Varies d) Hello is printed infinite times

Answer:d

101. What is the output of this C code?

#include

void main()

{

int i = 0;

while (i < 10)

{

i++;

printf("hi\n");

} while (i < 8)

i++;

printf("hello\n");

}

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

Answer:d

102. Example of iteration in C.

a) for b) while

c) do-while d) All of the mentioned

Answer:d

103. Number of times while loop condition is tested is, i is initialized to 0 in both case.

     while (i < n)

         i++;

    -------------

    do

         i++;

    while (i ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download