C Programming MCQ Vrushabh RT
C Programming MCQ Vrushabh RT
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. printf("Hello World! %d \n", x);
5. return 0;
6. }
a) Hello World! x;
b) Hello World! followed by a junk value
c) Compile time error
d) Hello World!
View Answer
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.)
Terminator21 C programming vrushabh
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int y = 10000;
5. int y = 34;
6. printf("Hello World! %d\n", y);
7. return 0;
8. }
a) Compile time error
b) Hello World! 34
c) Hello World! 1000
d) Hello World! followed by a junk value
View Answer
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
4. 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
View Answer
Answer: d
Explanation: #define PI 3.14 is a macro preprocessor, it is a textual
substitution.
5. What will happen if the following C code is executed?
1. #include <stdio.h>
2. int main()
3. {
4. int main = 3;
5. printf("%d", main);
6. return 0;
7. }
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
View Answer
Answer: c
Explanation: A C program can have same function name and same variable
name.
$ cc pgm3.c
Terminator21 C programming vrushabh
$ a.out
3
advertisement
float 3Bedroom-Hall-Kitchen?;
1. #include <stdio.h>
2. int main()
3. {
4. int ThisIsVariableName = 12;
5. int ThisIsVariablename = 14;
6. printf("%d", ThisIsVariablename);
7. return 0;
8. }
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
View Answer
Answer: b
Explanation: Variable names ThisIsVariablename and ThisIsVariableName are
both distinct as C is case sensitive.
Output:
$ cc pgm4.c
$ a.out
14
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int a[5] = {1, 2, 3, 4, 5};
5. int i;
6. for (i = 0; i < 5; i++)
7. if ((char)a[i] == '5')
8. printf("%d\n", a[i]);
9. else
10. printf("FAIL\n");
11. }
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
View Answer
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
FAIL
FAIL
FAIL
FAIL
FAIL
advertisement
2. The format identifier ‘%i’ is also used for _____ data type.
a) char
b) int
c) float
d) double
View Answer
Answer: b
Explanation: Both %d and %i can be used as a format identifier for int data
type.
3. Which data type is most suitable for storing a number 65000 in a 32-bit
system?
a) signed short
b) unsigned short
c) long
Terminator21 C programming vrushabh
d) int
View Answer
Answer: b
Explanation: 65000 comes in the range of short (16-bit) which occupies the
least memory. Signed short ranges from -32768 to 32767 and hence we
should use unsigned short.
4. 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
View Answer
Answer: d
Explanation: typedef and struct are used to define user-defined data types.
Join Sanfoundry@YouTube
1. #include <stdio.h>
2. int main()
3. {
4. signed char chr;
5. chr = 128;
6. printf("%d\n", chr);
7. return 0;
8. }
a) 128
b) -128
c) Depends on the compiler
d) None of the mentioned
View Answer
Answer: b
Explanation: signed char will be a negative number.
Output:
$ cc pgm2.c
$ a.out
-128
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. char c;
5. int i = 0;
6. FILE *file;
7. file = fopen("test.txt", "w+");
8. fprintf(file, "%c", 'a');
9. fprintf(file, "%c", -1);
10. fprintf(file, "%c", 'b');
11. fclose(file);
12. file = fopen("test.txt", "r");
13. while ((c = fgetc(file)) != -1)
14. printf("%c", c);
15. return 0;
16. }
a) a
b) Infinite loop
c) Depends on what fgetc returns
d) Depends on the compiler
View Answer
Answer: a
Explanation: None.
Output:
$ cc pgm3.c
$ a.out
a
8. 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
View Answer
Answer: c
Explanation: None.
advertisement
1. #include <stdio.h>
Terminator21 C programming vrushabh
2. int main()
3. {
4. float f1 = 0.1;
5. if (f1 == 0.1)
6. printf("equal\n");
7. else
8. printf("not equal\n");
9. }
a) equal
b) not equal
c) output depends on the compiler
d) error
View Answer
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
2. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. float f1 = 0.1;
5. if (f1 == 0.1f)
6. printf("equal\n");
7. else
8. printf("not equal\n");
9. }
a) equal
b) not equal
c) output depends on compiler
d) error
View Answer
Answer: a
Explanation: 0.1f results in 0.1 to be stored in floating point representations.
Output:
$ cc pgm5.c
$ a.out
equal
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int x = 10000;
5. double y = 56;
6. int *p = &x;
7. double *q = &y;
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. union Sti
3. {
4. int nu;
5. char m;
6. };
7. int main()
8. {
9. union Sti s;
10. printf("%d", sizeof(s));
11. return 0;
12. }
a) 8
b) 5
c) 9
d) 4
View Answer
Answer: d
Explanation: Since the size of a union is the size of its maximum data type,
here int is the largest data type. Hence the size of the union is 4.
Output:
$ cc pgm7.c
$ a.out
4
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. int main()
3. {
4. float x = 'a';
5. printf("%f", x);
6. return 0;
7. }
a) a
b) run time error
c) a.0000000
d) 97.000000
View Answer
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
7. Which of the data types has the size that is variable?
a) int
b) struct
c) float
d) double
View Answer
Answer: b
Explanation: Since the size of the structure depends on its fields, it has a
variable size.
advertisement
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. int main()
3. {
4. enum {ORANGE = 5, MANGO, BANANA = 4, PEACH};
5. printf("PEACH = %d\n", PEACH);
6. }
a) PEACH = 3
b) PEACH = 4
c) PEACH = 5
d) PEACH = 6
View Answer
Answer: c
Explanation: In enum, the value of constant is defined to the recent
assignment from left.
Output:
$ cc pgm1.c
$ a.out
PEACH = 5
2. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. printf("C programming %s", "Class by\n%s Sanfoundry",
"WOW");
5. }
a)
C programming Class by
WOW Sanfoundry
C programming Class by
%s Sanfoundry
advertisement
d) Compilation error
View Answer
Answer: c
Explanation: This program has only one %s within first double quotes, so it
does not read the string “WOW”.
The %s along with the Sanfoundry is not read as a format modifier while new
line character prints the new line.
Output:
$ cc pgm2.c
Terminator21 C programming vrushabh
$ a.out
C programming Class by
%s Sanfoundry
3. In the following code snippet, character pointer str holds a reference to the
string ___________
1. #include <stdio.h>
2. #define a 10
3. int main()
4. {
5. const int a = 5;
6. printf("a = %d\n", a);
7. }
a) a = 5
b) a = 10
c) Compilation error
d) Runtime error
View Answer
Answer: c
Explanation: The #define substitutes a with 10 without leaving any identifier,
which results in Compilation error.
Output:
$ cc pgm3.c
pgm3.c: In function ‘main’:
pgm3.c:5: error: expected identifier or ‘(’ before numeric constant
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int var = 010;
5. printf("%d", var);
6. }
a) 2
b) 8
c) 9
Terminator21 C programming vrushabh
d) 10
View Answer
Answer: b
Explanation: 010 is octal representation of 8.
Output:
$ cc pgm4.c
$ a.out
8
6. What will be the output of the following C function?
1. #include <stdio.h>
2. enum birds {SPARROW, PEACOCK, PARROT};
3. enum animals {TIGER = 8, LION, RABBIT, ZEBRA};
4. int main()
5. {
6. enum birds m = TIGER;
7. int k;
8. k = m;
9. printf("%d\n", k);
10. return 0;
11. }
a) 0
b) Compile time error
c) 1
d) 8
View Answer
Answer: d
Explanation: m is an integer constant, hence it is compatible.
Output:
$ cc pgm5.c
$ a.out
8
7. What will be the output of the following C code?
1. #include <stdio.h>
2. #define MAX 2
3. enum bird {SPARROW = MAX + 1, PARROT = SPARROW + MAX};
4. int main()
5. {
6. enum bird b = PARROT;
7. printf("%d\n", b);
8. return 0;
9. }
a) Compilation error
b) 5
c) Undefined value
d) 2
View Answer
Answer: b
Explanation: MAX value is 2 and hence PARROT will have value 3 + 2.
Output:
Terminator21 C programming vrushabh
$ cc pgm6.c
$ a.out
5
advertisement
1. #include <stdio.h>
2. #include <string.h>
3. int main()
4. {
5. char *str = "x";
6. char c = 'x';
7. char ary[1];
8. ary[0] = c;
9. printf("%d %d", strlen(str), strlen(ary));
10. return 0;
11. }
a) 1 1
b) 2 1
c) 2 2
d) 1 (undefined value)
View Answer
Answer: d
Explanation: str is null terminated, but ary is not null terminated.
Output:
$ cc pgm7.c
$ a.out
15
1. #include <stdio.h>
2. int main()
3. {
4. printf("sanfoundry\rclass\n");
5. return 0;
6. }
a) sanfoundryclass
b)
sanfoundry
class
c) classundry
d) sanfoundry
View Answer
Answer: c
Explanation: r is carriage return and moves the cursor back. sanfo is replaced
by class.
Output:
$ cc pgm8.c
$ a.out
classundry
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. printf("sanfoundry\r\nclass\n");
5. return 0;
6. }
a) sanfoundryclass
b)
sanfoundry
Terminator21 C programming vrushabh
class
c) classundry
d) sanfoundry
View Answer
Answer: b
Explanation: rn combination makes the cursor move to the next line.
Output:
$ cc pgm9.c
$ a.out
sanfoundry
class
4. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. const int p;
5. p = 4;
6. printf("p is %d", p);
7. return 0;
8. }
a) p is 4
b) Compile time error
c) Run time error
d) p is followed by a garbage value
View Answer
Answer: b
Explanation: Since the constant variable has to be declared and defined at
the same time, not doing it results in an error.
Output:
$ cc pgm10.c
pgm10.c: In function ‘main’:
pgm10.c:5: error: assignment of read-only variable ‘p’
5. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int k = 4;
5. int *const p = &k;
6. int r = 3;
7. p = &r;
8. printf("%d", p);
9. }
a) Address of k
b) Address of r
c) Compile time error
Terminator21 C programming vrushabh
d) Address of k + address of r
View Answer
Answer: c
Explanation: Since the pointer p is declared to be constant, trying to assign it
with a new value results in an error.
Output:
$ cc pgm11.c
pgm11.c: In function ‘main’:
pgm11.c:7: error: assignment of read-only variable ‘p’
pgm11.c:8: warning: format ‘%d’ expects type ‘int’, but argument 2 has type
‘int * const’
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int const k = 5;
5. k++;
6. printf("k is %d", k);
7. }
a) k is 6
b) Error due to const succeeding int
c) Error, because a constant variable can be changed only twice
d) Error, because a constant variable cannot be changed
View Answer
Answer: d
Explanation: Constant variable has to be declared and defined at the same
time. Trying to change it results in an error.
Output:
$ cc pgm12.c
pgm12.c: In function ‘main’:
pgm12.c:5: error: increment of read-only variable ‘k’
8. What will be the output of the following C code?
1. #include <stdio.h>
2. int const print()
3. {
Terminator21 C programming vrushabh
4. printf("Sanfoundry.com");
5. return 0;
6. }
7. void main()
8. {
9. print();
10. }
a) Error because function name cannot be preceded by const
b) Sanfoundry.com
c) Sanfoundry.com is printed infinite times
d) Blank screen, no output
View Answer
Answer: b
Explanation: None.
Output:
$ cc pgm13.c
$ a.out
advertisement
1. #include <stdio.h>
2. void foo(const int *);
3. int main()
4. {
5. const int i = 10;
6. printf("%d ", i);
7. foo(&i);
8. printf("%d", i);
9.
10. }
11. void foo(const int *i)
12. {
13. *i = 20;
14. }
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. int main()
3. {
4. const int i = 10;
5. int *ptr = &i;
6. *ptr = 20;
7. printf("%d\n", i);
8. return 0;
9. }
a) Compile time error
b) Compile time warning and printf displays 20
c) Undefined behaviour
d) 10
View Answer
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
Join Sanfoundry@YouTube
1. #include <stdio.h>
2. int main()
3. {
4. j = 10;
5. printf("%d\n", j++);
6. return 0;
7. }
a) 10
b) 11
c) Compile time error
Terminator21 C programming vrushabh
d) 0
View Answer
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.)
4. Will the following C code compile without any error?
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. for (int k = 0; k < 10; k++);
5. return 0;
6. }
a) Yes
b) No
c) Depends on the C standard implemented by compilers
d) Error
View Answer
Answer: c
Explanation: Compilers implementing C90 do 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
5. Will the following C code compile without any error?
1. #include <stdio.h>
2. int main()
3. {
4. int k;
5. {
6. int k;
7. for (k = 0; k < 10; k++);
8. }
9. }
a) Yes
b) No
c) Depends on the compiler
d) Depends on the C standard implemented by compilers
View Answer
Answer: a
Explanation: There can be blocks inside the block. But within a block,
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. int main()
3. {
4. char *var = "Advanced Training in C by Sanfoundry.com";
5. }
a) %f
b) %d
c) %c
d) %s
View Answer
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 for the variable var.
Answer: d
Explanation: char[] str is a declaration in Java, but not in C.
advertisement
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int k = 4;
5. float k = 4;
6. printf("%d", k)
7. }
a) Compile time error
b) 4
c) 4.0000000
d) 4.4
View Answer
Answer: a
Explanation: Since the variable k is defined both as integer and as float, it
results in an error.
Output:
$ cc pgm8.c
pgm8.c: In function ‘main’:
pgm8.c:5: error: conflicting types for ‘k’
pgm8.c:4: note: previous definition of ‘k’ was here
pgm8.c:6: warning: format ‘%d’ expects type ‘int’, but argument 2 has type
‘double’
pgm8.c:7: error: expected ‘;’ before ‘}’ token
Terminator21 C programming vrushabh
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int i = -3;
5. int k = i % 2;
6. printf("%d\n", k);
7. }
a) Compile time error
b) -1
c) 1
d) Implementation defined
View Answer
Answer: b
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 3;
5. int l = i / -2;
6. int k = i % -2;
7. printf("%d %d\n", l, k);
8. return 0;
9. }
a) Compile time error
b) -1 1
c) 1 -1
d) Implementation defined
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int i = 5;
5. i = i / 3;
6. printf("%d\n", i);
7. return 0;
8. }
a) Implementation defined
b) 1
c) 3
d) Compile time error
View Answer
Answer: b
Explanation: None.
Terminator21 C programming vrushabh
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int i = -5;
5. i = i / 3;
6. printf("%d\n", i);
7. return 0;
8. }
a) Implementation defined
b) -1
c) -3
d) Compile time error
View Answer
Answer: b
Explanation: None.
5. What will be the final value of x in the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int x = 5 * 9 / 3 + 9;
5. }
a) 3.75
b) Depends on compiler
c) 24
d) 3
View Answer
Answer: c
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int x = 5.3 % 2;
5. printf("Value of x is %d", x);
6. }
a) Value of x is 2.3
b) Value of x is 1
c) Value of x is 0.3
d) Compile time error
View Answer
Answer: d
Explanation: None.
7. What will be the output of the following C code?
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. void main()
3. {
4. int y = 3;
5. int x = 5 % 2 * 3 / 2;
6. printf("Value of x is %d", x);
7. }
a) Value of x is 1
b) Value of x is 2
c) Value of x is 3
d) Compile time error
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int a = 3;
5. int b = ++a + a++ + --a;
6. printf("Value of b is %d", b);
7. }
a) Value of x is 12
b) Value of x is 13
c) Value of x is 10
d) Undefined behaviour
View Answer
Answer: d
Explanation: None.
2. What is the precedence of arithmetic operators (from highest to lowest)?
a) %, *, /, +, –
b) %, +, /, *, –
c) +, -, %, *, /
d) %, +, -, *, /
View Answer
Answer: a
Explanation: None.
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. int main()
3. {
4. int a = 10;
5. double b = 5.6;
6. int c;
7. c = a + b;
8. printf("%d", c);
9. }
a) 15
b) 16
c) 15.6
d) 10
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int a = 10, b = 5, c = 5;
5. int d;
6. d = a == (b + c);
7. printf("%d", d);
8. }
a) Syntax error
b) 1
c) 10
d) 5
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int x = 1, y = 0, z = 5;
5. int a = x && y || z++;
6. printf("%d", z);
7. }
a) 6
b) 5
c) 0
d) Varies
View Answer
Answer: a
Explanation: None.
2. What will be the output of the following C code?
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. void main()
3. {
4. int x = 1, y = 0, z = 5;
5. int a = x && y && z++;
6. printf("%d", z);
7. }
a) 6
b) 5
c) 0
d) Varies
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int x = 1, y = 0, z = 3;
5. x > y ? printf("%d", z) : return z;
6. }
a) 3
b) 1
c) Compile time error
d) Run time error
View Answer
Answer: c
Explanation: None.
4. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int x = 1, z = 3;
5. int y = x << 3;
6. printf(" %d\n", y);
7. }
a) -2147483648
b) -1
c) Run time error
d) 8
View Answer
Answer: d
Explanation: None.
5. What will be the output of the following C code?
1. #include <stdio.h>
Terminator21 C programming vrushabh
2. void main()
3. {
4. int x = 0, y = 2, z = 3;
5. int a = x & y | z;
6. printf("%d", a);
7. }
a) 3
b) 0
c) 2
d) Run time error
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0, j = 0;
5. if (i && (j = i + 10))
6. //do something
7. ;
8. }
a) 0
b) 10
c) Depends on the compiler
d) Depends on language standard
View Answer
Answer: a
Explanation: None.
7. What will be the final value of j in the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 10, j = 0;
5. if (i || (j = i + 10))
6. //do something
7. ;
8. }
a) 0
b) 20
c) Compile time error
d) Depends on language standard
View Answer
Answer: a
Explanation: None.
8. What will be the output of the following C code?
1. #include <stdio.h>
Terminator21 C programming vrushabh
2. int main()
3. {
4. int i = 1;
5. if (i++ && (i == 1))
6. printf("Yes\n");
7. else
8. printf("No\n");
9. }
a) Yes
b) No
c) Depends on the compiler
d) Depends on the standard
View Answer
Answer: b
Explanation: None.
2. Do logical operators in the C language are evaluated with the short circuit?
a) True
b) False
c) Depends on the compiler
d) Depends on the standard
View Answer
Answer: a
Explanation: None.
3. What is the result of logical or relational expression in C?
a) True or False
b) 0 or 1
c) 0 if an expression is false and any positive number if an expression is true
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. int main()
3. {
4. int a = 10, b = 5, c = 5;
5. int d;
6. d = b + c == a;
7. printf("%d", d);
8. }
a) Syntax error
b) 1
c) 5
d) 10
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int a = 10, b = 5, c = 3;
5. b != !a;
6. c = !!a;
7. printf("%d\t%d", b, c);
8. }
a) 5 1
b) 0 3
c) 5 3
d) 1 1
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int a = 10;
5. if (a == a--)
6. printf("TRUE 1\t");
7. a = 10;
8. if (a == --a)
9. printf("TRUE 2\t");
10. }
a) TRUE 1
b) TRUE 2
c) TRUE 1 TRUE 2
d) Compiler Dependent
View Answer
Answer: d
Explanation: This is a sequence point problem and hence the result will be
implementation dependent.
advertisement
advertisement
1. #include <stdio.h>
2. void main()
3. {
Terminator21 C programming vrushabh
4. float x = 0.1;
5. if (x == 0.1)
6. printf("Sanfoundry");
7. else
8. printf("Advanced C Classes");
9. }
a) Advanced C Classes
b) Sanfoundry
c) Run time error
d) Compile time error
View Answer
Answer: a
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. float x = 0.1;
5. printf("%d, ", x);
6. printf("%f", x);
7. }
a) 0.100000, junk value
b) Junk value, 0.100000
c) 0, 0.100000
d) 0, 0.999999
View Answer
Answer: b
Explanation: None.
3. What will be the output of the following C code? (Initial values: x= 7, y = 8)
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. float x;
5. int y;
6. printf("enter two numbers \n", x);
7. scanf("%f %f", &x, &y);
8. printf("%f, %d", x, y);
9. }
a) 7.000000, 7
b) Run time error
c) 7.000000, junk
d) Varies
View Answer
Answer: c
Explanation: None.
4. What will be the output of the following C code?
advertisement
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. void main()
3. {
4. double x = 123828749.66;
5. int y = x;
6. printf("%d\n", y);
7. printf("%lf\n", y);
8. }
a) 0, 0.0
b) 123828749, 123828749.66
c) 12382874, 12382874.0
d) 123828749, 0.000000
View Answer
Answer: d
Explanation: None.
5. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int x = 97;
5. char y = x;
6. printf("%c\n", y);
7. }
a) a
b) b
c) 97
d) Run time error
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. unsigned int i = 23;
5. signed char c = -23;
6. if (i > c)
7. printf("Yes\n");
8. else if (i < c)
9. printf("No\n");
10. }
Terminator21 C programming vrushabh
a) Yes
b) No
c) Depends on the compiler
d) Depends on the operating system
View Answer
Answer: b
Explanation: None.
8. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 23;
5. char c = -23;
6. if (i < c)
7. printf("Yes\n");
8. else
9. printf("No\n");
10. }
a) Yes
b) No
c) Depends on the compiler
d) Depends on the standard
View Answer
Answer: b
Explanation: None.
2. What will be the output of the following C code considering the size of a
short int is 2, char is 1 and int is 4 bytes?
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. int main()
3. {
4. short int i = 20;
5. char c = 97;
6. printf("%d, %d, %d\n", sizeof(i), sizeof(c), sizeof(c +
i));
7. return 0;
8. }
a) 2, 1, 2
b) 2, 1, 1
c) 2, 1, 4
d) 2, 2, 8
View Answer
Answer: c
Explanation: None.
3. Which type of 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
View Answer
Answer: b
Explanation: Conversion of a float to pointer type is not allowed.
Join Sanfoundry@YouTube
4. What will be the data type of the result of the following operation?
advertisement
1. #include <stdio.h> //Program 1
2. int main()
3. {
4. int d, a = 1, b = 2;
5. d = a++ + ++b;
6. printf("%d %d %d", d, a, b);
7. }
1. #include <stdio.h> //Program 2
2. int main()
3. {
4. int d, a = 1, b = 2;
5. d = a++ +++b;
6. printf("%d %d %d", d, a, b);
7. }
a) No difference as space doesn’t make any difference, values of a, b, d are
same in both the case
b) Space does make a difference, values of a, b, d are different
Terminator21 C programming vrushabh
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int a = 1, b = 1, c;
5. c = a++ + b;
6. printf("%d, %d", a, b);
7. }
a) a = 1, b = 1
b) a = 2, b = 1
c) a = 1, b = 2
d) a = 2, b = 2
View Answer
Answer: b
Explanation: None.
3. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int a = 1, b = 1, d = 1;
5. printf("%d, %d, %d", ++a + ++a+a++, a++ + ++b, ++d + d++ +
a++);
6. }
a) 15, 4, 5
b) 9, 6, 9
c) 9, 3, 5
d) Undefined (Compiler Dependent)
View Answer
Answer: d
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int a = 10, b = 10;
5. if (a = 5)
6. b--;
7. printf("%d, %d", a, b--);
8. }
a) a = 10, b = 9
b) a = 10, b = 8
c) a = 5, b = 9
d) a = 5, b = 8
View Answer
Answer: c
Explanation: None.
6. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. int j = i++ + i;
6. printf("%d\n", j);
7. }
a) 0
b) 1
c) 2
d) Compile time error
View Answer
Answer: b
Explanation: None.
7. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 2;
5. int j = ++i + i;
6. printf("%d\n", j);
7. }
a) 6
b) 5
c) 4
d) Compile time error
View Answer
Answer: a
Explanation: None.
8. What will be the output of the following C code?
1. #include <stdio.h>
Terminator21 C programming vrushabh
2. int main()
3. {
4. int i = 2;
5. int i = i++ + i;
6. printf("%d\n", i);
7. }
a) = operator is not a sequence point
b) ++ operator may return value with or without side effects
c) it can be evaluated as (i++)+i or i+(++i)
d) = operator is a sequence point
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. int x = i++, y = ++i;
6. printf("%d % d\n", x, y);
7. return 0;
8. }
a) 0, 2
b) 0, 1
c) 1, 2
d) Undefined
View Answer
Answer: a
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 10;
Terminator21 C programming vrushabh
5. int *p = &i;
6. printf("%d\n", *p++);
7. }
a) 10
b) 11
c) Garbage value
d) Address of i
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int x = 97;
5. int y = sizeof(x++);
6. printf("X is %d", x);
7. }
a) X is 97
b) X is 98
c) X is 99
d) Run time error
View Answer
Answer: a
Explanation: None.
4. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int x = 4, y, z;
5. y = --x;
6. z = x--;
7. printf("%d%d%d", x, y, z);
8. }
a) 3 2 3
b) 2 3 3
c) 3 2 2
d) 2 3 4
View Answer
Answer: b
Explanation: None.
5. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
Terminator21 C programming vrushabh
4. int x = 4;
5. int *p = &x;
6. int *k = p++;
7. int r = p - k;
8. printf("%d", r);
9. }
a) 4
b) 8
c) 1
d) Run time error
View Answer
Answer: c
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int a = 5, b = -7, c = 0, d;
5. d = ++a && ++b || ++c;
6. printf("\n%d%d%d%d", a, b, c, d);
7. }
a) 6 -6 0 0
b) 6 -5 0 1
c) -6 -6 0 1
d) 6 -6 0 1
View Answer
Answer: d
Explanation: None.
7. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int a = -5;
5. int k = (a++, ++a);
6. printf("%d\n", k);
7. }
a) -4
b) -5
c) 4
d) -3
View Answer
Answer: d
Explanation: None.
Terminator21 C programming vrushabh
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int c = 2 ^ 3;
5. printf("%d\n", c);
6. }
a) 1
b) 8
c) 9
d) 0
View Answer
Answer: a
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. unsigned int a = 10;
5. a = ~a;
6. printf("%d\n", a);
7. }
a) -9
b) -10
c) -11
d) 10
View Answer
Answer: c
Explanation: None.
advertisement
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. int main()
3. {
4. if (7 & 8)
5. printf("Honesty");
6. if ((~7 & 0x000f) == 8)
7. printf("is the best policy\n");
8. }
a) Honesty is the best policy
b) Honesty
c) is the best policy
d) No output
View Answer
Answer: c
Explanation: None.
4. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int a = 2;
5. if (a >> 1)
6. printf("%d\n", a);
7. }
a) 0
b) 1
c) 2
d) No Output
View Answer
Answer: c
Explanation: None.
5. Comment on the output of the following C code.
1. #include <stdio.h>
2. int main()
3. {
4. int i, n, a = 4;
5. scanf("%d", &n);
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. void main()
3. {
4. int x = 97;
5. int y = sizeof(x++);
6. printf("x is %d", x);
7. }
a) x is 97
b) x is 98
c) x is 99
d) Run time error
View Answer
Answer: a
Explanation: None.
7. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int x = 4, y, z;
5. y = --x;
6. z = x--;
7. printf("%d%d%d", x, y, z);
8. }
a) 3 2 3
b) 2 2 3
c) 3 2 2
d) 2 3 3
View Answer
Answer: d
Explanation: None.
8. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int x = 4;
5. int *p = &x;
Terminator21 C programming vrushabh
6. int *k = p++;
7. int r = p - k;
8. printf("%d", r);
9. }
a) 4
b) 8
c) 1
d) Run time error
View Answer
Answer: c
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int a = 5, b = -7, c = 0, d;
5. d = ++a && ++b || ++c;
6. printf("\n%d%d%d%d", a, b, c, d);
7. }
a) 6 -6 0 0
b) 6 -5 0 1
c) -6 -6 0 1
d) 6 -6 0 1
View Answer
Answer: d
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int a = -5;
5. int k = (a++, ++a);
6. printf("%d\n", k);
7. }
a) -3
b) -5
Terminator21 C programming vrushabh
c) 4
d) Undefined
View Answer
Answer: a
Explanation: None.
Join Sanfoundry@YouTube
1. #include <stdio.h>
2. int main()
3. {
4. int x = 2;
5. x = x << 1;
6. printf("%d\n", x);
7. }
a) 4
b) 1
c) Depends on the compiler
d) Depends on the endianness of the machine
View Answer
Answer: a
Explanation: None.
4. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int x = -2;
5. x = x >> 1;
6. printf("%d\n", x);
7. }
a) 1
b) -1
c) 2 31 – 1 considering int to be 4 bytes
d) Either -1 or 1
View Answer
Answer: b
Explanation: None.
5. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. if (~0 == 1)
5. printf("yes\n");
6. else
7. printf("no\n");
8. }
Terminator21 C programming vrushabh
a) yes
b) no
c) compile time error
d) undefined
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int x = -2;
5. if (!0 == 1)
6. printf("yes\n");
7. else
8. printf("no\n");
9. }
a) yes
b) no
c) run time error
d) undefined
View Answer
Answer: a
Explanation: None.
7. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int y = 0;
5. if (1 |(y = 1))
6. printf("y is %d\n", y);
7. else
8. printf("%d\n", y);
9.
10. }
a) y is 1
b) 1
c) run time error
d) undefined
View Answer
Answer: a
Explanation: None.
8. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int y = 1;
Terminator21 C programming vrushabh
5. if (y & (y = 2))
6. printf("true %d\n", y);
7. else
8. printf("false %d\n", y);
9.
10. }
a) true 2
b) false 2
c) either true 2 or false 2
d) true 1
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int x = 0;
5. if (x = 0)
6. printf("Its zero\n");
7. else
8. printf("Its not zero\n");
9. }
a) Its not zero
b) Its zero
c) Run time error
d) None
View Answer
Answer: a
Explanation: None.
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. void main()
3. {
4. int k = 8;
5. int x = 0 == 1 && k++;
6. printf("%d%d\n", x, k);
7. }
a) 0 9
b) 0 8
c) 1 8
d) 1 9
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. char a = 'a';
5. int x = (a % 10)++;
6. printf("%d\n", x);
7. }
a) 6
b) Junk value
c) Compile time error
d) 7
View Answer
Answer: c
Explanation: None.
4. What will be the output of the following C code snippet?
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. 1 < 2 ? return 1: return 2;
5. }
a) returns 1
b) returns 2
c) Varies
d) Compile time error
View Answer
Answer: d
Explanation: None.
5. What will be the output of the following C code snippet?
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. void main()
3. {
4. unsigned int x = -5;
5. printf("%d", x);
6. }
a) Run time error
b) Aries
c) -5
d) 5
View Answer
Answer: c
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int x = 2, y = 1;
5. x *= x + y;
6. printf("%d\n", x);
7. return 0;
8. }
a) 5
b) 6
c) Undefined behaviour
d) Compile time error
View Answer
Answer: b
Explanation: None.
7. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int x = 2, y = 2;
5. x /= x / y;
6. printf("%d\n", x);
7. return 0;
8. }
a) 2
b) 1
c) 0.5
d) Undefined behaviour
View Answer
Answer: a
Explanation: None.
8. What will be the output of the following C code?
1. #include <stdio.h>
Terminator21 C programming vrushabh
2. int main()
3. {
4. int x = 1, y = 0;
5. x &&= y;
6. printf("%d\n", x);
7. }
a) Compile time error
b) 1
c) 0
d) Undefined behaviour
View Answer
Answer: a
Explanation: None.
y = x + y;
advertisement
a) int
b) float
c) there is no type for an assignment expression
d) double
View Answer
Answer: a
Explanation: None.
2. What will be the value of the following assignment expression?
a) 2
b) True
c) 1
d) 0
View Answer
Terminator21 C programming vrushabh
Answer: a
Explanation: None.
3. Operation “a = a * b + a” can also be written as ___________
a) a *= b + 1;
b) (c = a * b)!=(a = c + a);
c) a = (b + 1)* a;
d) All of the mentioned
View Answer
Answer: d
Explanation: None.
advertisement
4. What will be the final value of c in the following C statement? (Initial value:
c = 2)
1.c <<= 1;
a) c = 1;
b) c = 2;
c) c = 3;
d) c = 4;
View Answer
Answer: d
Explanation: None.
5. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int a = 1, b = 2;
5. a += b -= a;
6. printf("%d %d", a, b);
7. }
a) 1 1
b) 1 2
c) 2 1
d) 2 2
View Answer
Answer: c
Explanation: None.
6. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int a = 4, n, i, result = 0;
5. scanf("%d", n);
6. for (i = 0;i < n; i++)
7. result += a;
8. }
Terminator21 C programming vrushabh
a) Addition of a and n
b) Subtraction of a and n
c) Multiplication of a and n
d) Division of a and n
View Answer
Answer: c
Explanation: None.
advertisement
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int x = 2, y = 0;
5. int z = (y++) ? y == 1 && x : 0;
6. printf("%d\n", z);
7. return 0;
8. }
a) 0
b) 1
c) Undefined behaviour
d) Compile time error
View Answer
Terminator21 C programming vrushabh
Answer: a
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int x = 1;
5. int y = x == 1 ? getchar(): 2;
6. printf("%d\n", y);
7. }
a) Compile time error
b) Whatever character getchar function returns
c) Ascii value of character getchar function returns
d) 2
View Answer
Answer: c
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int x = 1;
5. short int i = 2;
6. float f = 3;
7. if (sizeof((x == 2) ? f : i) == sizeof(float))
8. printf("float\n");
9. else if (sizeof((x == 2) ? f : i) == sizeof(short int))
10. printf("short int\n");
11. }
a) float
b) short int
c) Undefined behaviour
d) Compile time error
View Answer
Answer: a
Explanation: None.
4. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int a = 2;
5. int b = 0;
6. int y = (b == 0) ? a :(a > b) ? (b = 1): a;
7. printf("%d\n", y);
8. }
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. int main()
3. {
4. int y = 1, x = 0;
5. int l = (y++, x++) ? y : x;
6. printf("%d\n", l);
7. }
a) 1
b) 2
c) Compile time error
d) Undefined behaviour
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int k = 8;
5. int m = 7;
6. int z = k < m ? k++ : m++;
7. printf("%d", z);
8. }
a) 7
b) 8
c) Run time error
d) 15
View Answer
Answer: a
Explanation: None.
7. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int k = 8;
5. int m = 7;
6. int z = k < m ? k = m : m++;
7. printf("%d", z);
8. }
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. void main()
3. {
4. 1 < 2 ? return 1 : return 2;
5. }
a) returns 1
b) returns 2
c) Varies
d) Compile time error
View Answer
Answer: d
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int k = 8;
5. int m = 7;
6. k < m ? k++ : m = k;
7. printf("%d", k);
8. }
a) 7
b) 8
c) Compile time error
d) Run time error
View Answer
Terminator21 C programming vrushabh
Answer: c
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int k = 8;
5. int m = 7;
6. k < m ? k = k + 1 : m = m + 1;
7. printf("%d", k);
8. }
a) Compile time error
b) 9
c) 8
d) Run time error
View Answer
Answer: a
Explanation: None.
3. What will be the final values of a and c in the following C statement? (Initial
values: a = 2, c = 1)
advertisement
c = (c) ? a = 0 : 2;
a) a = 0, c = 0;
b) a = 2, c = 2;
c) a = 2, c = 2;
d) a = 1, c = 2;
View Answer
Answer: a
Explanation: None.
4. What will be the data type of the following expression? (Initial data type: a
= int, var1 = double, var2 = float)
a) exp1
b) exp2
Terminator21 C programming vrushabh
c) exp3
d) all of the mentioned
View Answer
Answer: d
Explanation: None.
advertisement
6. What will be the final value of c in the following C code snippet? (Initial
values: a = 1, b = 2, c = 1)
c += (-c) ? a : b;
a) Syntax Error
b) c = 1
c) c = 2
d) c = 3
View Answer
Answer: c
Explanation: None.
7. The following C code can be rewritten as _______
c = (n) ? a : b;
a)
if (!n)c = b;
else c = a;
b)
advertisement
if (n <;= 0)c = b;
else c = a;
c)
if (n > 0)c = a;
else c = b;
d) All of the mentioned
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. reverse(1);
5. }
6. void reverse(int i)
7. {
8. if (i > 5)
9. exit(0);
10. printf("%d\n", i);
11. return reverse(i++);
12. }
a) 1 2 3 4 5
b) 1 2 3 4
c) Compile time error
d) Stack overflow
View Answer
Answer: d
Explanation: None.
2. What will be the output of the following C function?
1. #include <stdio.h>
2. void reverse(int i);
3. int main()
4. {
5. reverse(1);
6. }
7. void reverse(int i)
8. {
9. if (i > 5)
10. return ;
11. printf("%d ", i);
12. return reverse((i++, i));
13. }
a) 1 2 3 4 5
b) Segmentation fault
c) Compilation error
d) Undefined behaviour
View Answer
Terminator21 C programming vrushabh
Answer: a
Explanation: None.
3. In expression i = g() + f(), first function called depends on __________
a) Compiler
b) Associativiy of () operator
c) Precedence of () and + operator
d) Left to write of the expression
View Answer
Answer: a
Explanation: None.
Join Sanfoundry@YouTube
1. #include <stdio.h>
2. int x = 0;
3. int main()
4. {
5. int i = (f() + g()) || g();
6. int j = g() || (f() + g());
7. }
8. int f()
9. {
10. if (x == 0)
11. return x + 1;
12. else
13. return x - 1;
14. }
15. int g()
16. {
17. return x++;
18. }
a) i value is 1 and j value is 1
b) i value is 0 and j value is 0
c) i value is 1 and j value is undefined
d) i and j value are undefined
View Answer
Answer: d
Explanation: None.
5. What will be the final values of i and j in the following C code?
1. #include <stdio.h>
2. int x = 0;
3. int main()
4. {
5. int i = (f() + g()) | g(); //bitwise or
6. int j = g() | (f() + g()); //bitwise or
7. }
8. int f()
9. {
10. if (x == 0)
11. return x + 1;
12. else
13. return x - 1;
Terminator21 C programming vrushabh
14. }
15. int g()
16. {
17. return x++;
18. }
a) i value is 1 and j value is 1
b) i value is 0 and j value is 0
c) i value is 1 and j value is undefined
d) i and j value are undefined
View Answer
6. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int x = 2, y = 0;
5. int z = y && (y |= 10);
6. printf("%d\n", z);
7. return 0;
8. }
a) 1
b) 0
c) Undefined behaviour due to order of evaluation
d) 2
View Answer
Answer: b
Explanation: None.
7. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int x = 2, y = 0;
5. int z = (y++) ? 2 : y == 1 && x;
6. printf("%d\n", z);
7. return 0;
8. }
a) 0
b) 1
c) 2
d) Undefined behaviour
View Answer
Answer: b
Explanation: None.
8. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int x = 2, y = 0;
5. int z;
Terminator21 C programming vrushabh
6. z = (y++, y);
7. printf("%d\n", z);
8. return 0;
9. }
a) 0
b) 1
c) Undefined behaviour
d) Compilation error
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int x = 2, y = 0, l;
5. int z;
6. z = y = 1, l = x && y;
7. printf("%d\n", l);
8. return 0;
9. }
a) 0
b) 1
c) Undefined behaviour due to order of evaluation can be different
d) Compilation error
View Answer
Answer: b
Explanation: None.
10. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int y = 2;
5. int z = y +(y = 10);
6. printf("%d\n", z);
7. }
a) 12
b) 20
c) 4
d) Either 12 or 20
View Answer
Answer: b
Explanation: None.
Terminator21 C programming vrushabh
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int x = 2, y = 2;
5. float f = y + x /= x / y;
6. printf("%d %f\n", x, f);
7. return 0;
8. }
a) 2 4.000000
b) Compile time error
c) 2 3.500000
d) Undefined behaviour
View Answer
Answer: b
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int x = 1, y = 2;
5. if (x && y == 1)
6. printf("true\n");
7. else
8. printf("false\n");
9. }
a) true
b) false
c) compile time error
d) undefined behaviour
View Answer
Answer: b
Explanation: None.
3. What will be the output of the following C code?
Terminator21 C programming vrushabh
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int x = 1, y = 2;
5. int z = x & y == 2;
6. printf("%d\n", z);
7. }
a) 0
b) 1
c) Compile time error
d) Undefined behaviour
View Answer
Answer: b
Explanation: None.
4. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int x = 3, y = 2;
5. int z = x /= y %= 2;
6. printf("%d\n", z);
7. }
a) 1
b) Compile time error
c) Floating point exception
d) Segmentation fault
View Answer
Answer: c
Explanation: None.
5. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int x = 3, y = 2;
5. int z = x << 1 > 5;
6. printf("%d\n", z);
7. }
a) 1
b) 0
c) 3
d) Compile time error
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int x = 3; //, y = 2;
5. const int *p = &x;
6. *p++;
7. printf("%d\n", *p);
8. }
a) Increment of read-only location compile error
b) 4
c) Some garbage value
d) Undefined behaviour
View Answer
Answer: c
Explanation: None.
7. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int x = 2, y = 2;
5. int z = x ^ y & 1;
6. printf("%d\n", z);
7. }
a) 1
b) 2
c) 0
d) 1 or 2
View Answer
Answer: b
Explanation: None.
8. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int x = 2, y = 0;
5. int z = x && y = 1;
6. printf("%d\n", z);
7. }
a) 0
b) 1
c) Compile time error
d) 2
View Answer
Answer: c
Explanation: None.
9. What will be the output of the following C code?
1. #include <stdio.h>
Terminator21 C programming vrushabh
2. int main()
3. {
4. int x = 0, y = 2;
5. if (!x && y)
6. printf("true\n");
7. else
8. printf("false\n");
9. }
a) True
b) False
c) Compile time error
d) Undefined behaviour
View Answer
Answer: a
Explanation: None.
10. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int x = 0, y = 2;
5. int z = ~x & y;
6. printf("%d\n", z);
7. }
a) -1
b) 2
c) 0
d) Compile time error
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int a = 5 * 3 + 2 - 4;
5. printf("%d", a);
6. }
a) 13
b) 14
c) 12
d) 1 6
View Answer
Answer: a
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int a = 2 + 4 + 3 * 5 / 3 - 5;
5. printf("%d", a);
6. }
a) 7
b) 6
c) 10
d) 9
View Answer
Answer: b
Explanation: None.
3. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int a = 5 * 3 % 6 - 8 + 3;
5. printf("%d", a);
6. }
a) 10
b) 2
c) -2
d) -3
View Answer
Answer: c
Explanation: None.
4. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
Terminator21 C programming vrushabh
4. int b = 6;
5. int c = 7;
6. int a = ++b + c--;
7. printf("%d", a);
8. }
a) Run time error
b) 15
c) 13
d) 14
View Answer
Answer: d
Explanation: None.
5. What will be the output of the following C code?
1. #include <stdio.h>
2. void main(
3. {
4. double b = 8;
5. b++;
6. printf("%lf", b);
7. }
a) 9.000000
b) 9
c) 9.0
d) Run time error
View Answer
Answer: a
Explanation: None.
6. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. double b = 3 % 0 * 1 - 4 / 2;
5. printf("%lf", b);
6. }
a) -2
b) Floating point Exception
c) 1
d) 0
View Answer
Answer: b
Explanation: None.
7. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. double b = 5 % 3 & 4 + 5 * 6;
5. printf("%lf", b);
Terminator21 C programming vrushabh
6. }
a) 2
b) 30
c) 2.000000
d) Run time error
View Answer
Answer: c
Explanation: None.
8. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. double b = 3 && 5 & 4 % 3;
5. printf("%lf", b);
6. }
a) 3.000000
b) 4.000000
c) 5.000000
d) 1.000000
View Answer
Answer: d
Explanation: None.
9. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. double b = 5 & 3 && 4 || 5 | 6;
5. printf("%lf", b);
6. }
a) 1.000000
b) 0.000000
c) 7.000000
d) 2.000000
View Answer
Answer: a
Explanation: None.
10. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int k = 0;
5. double b = k++ + ++k + k--;
6. printf("%d", k);
7. }
a) 6
b) 1
Terminator21 C programming vrushabh
c) 5
d) undefined
View Answer
Answer: d
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int b = 5 - 4 + 2 * 5;
5. printf("%d", b);
6. }
a) 25
b) -5
c) 11
d) 16
View Answer
2. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int b = 5 & 4 & 6;
5. printf("%d", b);
6. }
a) 5
b) 6
c) 3
d) 4
View Answer
Answer: d
Explanation: None.
3. What will be the output of the following C code?
Terminator21 C programming vrushabh
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int b = 5 & 4 | 6;
5. printf("%d", b);
6. }
a) 6
b) 4
c) 1
d) 0
View Answer
Answer: a
Explanation: None.
4. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int b = 5 + 7 * 4 - 9 * (3, 2);
5. printf("%d", b);
6. }
a) 6
b) 15
c) 13
d) 21
View Answer
Answer: b
Explanation: None.
5. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int h = 8;
5. int b = (h++, h++);
6. printf("%d%d\n", b, h);
7. }
a) 10 10
b) 10 9
c) 9 10
d) 8 10
View Answer
Answer: c
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
Terminator21 C programming vrushabh
3. {
4. int h = 8;
5. int b = h++ + h++ + h++;
6. printf("%d\n", h);
7. }
a) 9
b) 10
c) 12
d) 11
View Answer
Answer: d
Explanation: None.
7. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int h = 8;
5. int b = 4 * 6 + 3 * 4 < 3 ? 4 : 3;
6. printf("%d\n", b);
7. }
a) 3
b) 33
c) 34
d) Run time error
View Answer
Answer: a
Explanation: None.
8. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int a = 2 + 3 - 4 + 8 - 5 % 4;
5. printf("%d\n", a);
6. }
a) 0
b) 8
c) 11
d) 9
View Answer
Answer: b
Explanation: None.
9. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. char a = '0';
5. char b = 'm';
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. void main()
3. {
4. char a = 'A';
5. char b = 'B';
6. int c = a + b % 3 - 3 * 2;
7. printf("%d\n", c);
8. }
a) 65
b) 58
c) 64
d) 59
View Answer
Answer: d
Explanation: None.
d) +=
View Answer
Answer: d
Explanation: None.
advertisement
advertisement
n = 1;
printf("%d, %dn", 3*n, n++);
a) Output will be 3, 2
b) Output will be 3, 1
c) Output will be 6, 1
d) Output is compiler dependent
View Answer
Answer: d
Explanation: None.
4. Which of the following option is the correct representation of the following
C statement?
e = a * b + c / d * f;
a) e = (a * (b +(c /(d * f))));
b) e = ((a * b) + (c / (d * f)));
c) e = ((a * b) + ((c / d)* f));
d) Both e = ((a * b) + (c / (d * f))); and e = ((a * b) + ((c / d)* f));
View Answer
Answer: d
Explanation: Verified by e = 1 * 2 + 3 / 4 * 5; and then using respective
braces according to the option.
advertisement
b = (b / a);
a = a * b;
b = a / b;
Terminator21 C programming vrushabh
1. #include<stdio.h>
2. int main()
3. {
4. int a = 1, b = 2, c = 3, d = 4, e;
5. e = c + d = b * a;
6. printf("%d, %d\n", e, d);
7. }
a) 7, 4
b) 7, 2
c) 5, 2
d) Syntax error
View Answer
Answer: d
Explanation: None.
advertisement
7. Which of the following is the correct order of evaluation for the given
expression?
a = w % x / y * z;
a) % / * =
b) / * % =
c) = % * /
d) * % / =
View Answer
Answer: a
Explanation: None.
8. Which function in the following expression will be called first?
b) sizeof
c) *
d) +
View Answer
Answer: a
Explanation: None.
10. Which of the following is a ternary operator?
a) &&
b) >>=
c) ?:
d) ->
View Answer
Answer: c
Explanation: None.
b) Left to Right
c) Random fashion
d) Both Right to Left and Left to Right
View Answer
Answer: d
Explanation: None.
4. Which of the following method is accepted for assignment?
a) 5 = a = b = c = d;
b) a = b = c = d = 5;
c) a = b = 5 = c = d;
d) None of the mentioned
View Answer
Answer: b
Explanation: None.
5. Which of the following is NOT possible with any 2 operators in C?
a) Different precedence, same associativity
b) Different precedence, different associativity
c) Same precedence, different associativity
d) All of the mentioned
View Answer
Answer: c
Explanation: None.
advertisement
Answer: d
Explanation: None.
8. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int x = 3, i = 0;
5. do {
6. x = x++;
7. i++;
8. } while (i != 3);
9. printf("%d\n", x);
10. }
a) Undefined behaviour
b) Output will be 3
c) Output will be 6
d) Output will be 5
View Answer
Answer: c
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int a = -1, b = 4, c = 1, d;
5. d = ++a && ++b || ++c;
6. printf("%d, %d, %d, %d\n", a, b, c, d);
7. return 0;
8. }
a) 0, 4, 2, 1
b) 0, 5, 2, 1
c) -1, 4, 1, 1
d) 0, 5, 1, 0
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int p = 10, q = 20, r;
5. if (r = p = 5 || q > 20)
6. printf("%d", r);
7. else
8. printf("No Output\n");
9. }
Terminator21 C programming vrushabh
a) 1
b) 10
c) 20
d) No Output
View Answer
Answer: a
Explanation: None.
Terminator21 C programming vrushabh
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int x = 5;
5. if (x < 1)
6. printf("hello");
7. if (x == 5)
8. printf("hi");
9. else
10. printf("no");
11. }
a) hi
b) hello
c) no
d) error
View Answer
Answer: a
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
2. int x;
3. void main()
Terminator21 C programming vrushabh
4. {
5. if (x)
6. printf("hi");
7. else
8. printf("how are u");
9. }
a) hi
b) how are you
c) compile time error
d) error
View Answer
Answer: b
Explanation: None.
3. What will be the output of the following C code?
Join Sanfoundry@YouTube
1. #include <stdio.h>
2. void main()
3. {
4. int x = 5;
5. if (true);
6. printf("hello");
7. }
a) It will display hello
b) It will throw an error
c) Nothing will be displayed
d) Compiler dependent
View Answer
Answer: b
Explanation: None.
4. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int x = 0;
5. if (x == 0)
6. printf("hi");
7. else
8. printf("how are u");
9. printf("hello");
10. }
a) hi
b) how are you
c) hello
d) hihello
View Answer
Answer: d
Explanation: None.
5. What will be the output of the following C code?
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. void main()
3. {
4. int x = 5;
5. if (x < 1);
6. printf("Hello");
7.
8. }
a) Nothing
b) Run time error
c) Hello
d) Varies
View Answer
Answer: c
Explanation: None.
advertisement
6. What will be the output of the following C code? (Assuming that we have
entered the value 1 in the standard input)
1. #include <stdio.h>
2. void main()
3. {
4. double ch;
5. printf("enter a value between 1 to 2:");
6. scanf("%lf", &ch);
7. switch (ch)
8. {
9. case 1:
10. printf("1");
11. break;
12. case 2:
13. printf("2");
14. break;
15. }
16. }
a) Compile time error
b) 1
c) 2
d) Varies
View Answer
Answer: a
Explanation: None.
7. What will be the output of the following C code? (Assuming that we have
entered the value 1 in the standard input)
1. #include <stdio.h>
2. void main()
3. {
4. char *ch;
5. printf("enter a value between 1 to 3:");
6. scanf("%s", ch);
7. switch (ch)
8. {
9. case "1":
Terminator21 C programming vrushabh
10. printf("1");
11. break;
12. case "2":
13. printf("2");
14. break;
15. }
16. }
a) 1
b) 2
c) Compile time error
d) No Compile time error
View Answer
Answer: c
Explanation: None.
8. What will be the output of the following C code? (Assuming that we have
entered the value 1 in the standard input)
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int ch;
5. printf("enter a value between 1 to 2:");
6. scanf("%d", &ch);
7. switch (ch)
8. {
9. case 1:
10. printf("1\n");
11. default:
12. printf("2\n");
13. }
14. }
a) 1
b) 2
c) 1 2
d) Run time error
View Answer
Answer: c
Explanation: None.
9. What will be the output of the following C code? (Assuming that we have
entered the value 2 in the standard input)
1. #include <stdio.h>
2. void main()
3. {
4. int ch;
5. printf("enter a value between 1 to 2:");
6. scanf("%d", &ch);
7. switch (ch)
8. {
9. case 1:
10. printf("1\n");
11. break;
12. printf("Hi");
Terminator21 C programming vrushabh
13. default:
14. printf("2\n");
15. }
16. }
a) 1
b) Hi 2
c) Run time error
d) 2
View Answer
Answer: d
Explanation: None.
10. What will be the output of the following C code? (Assuming that we have
entered the value 1 in the standard input)
1. #include <stdio.h>
2. void main()
3. {
4. int ch;
5. printf("enter a value between 1 to 2:");
6. scanf("%d", &ch);
7. switch (ch, ch + 1)
8. {
9. case 1:
10. printf("1\n");
11. break;
12. case 2:
13. printf("2");
14. break;
15. }
16. }
a) 1
b) 2
c) 3
d) Run time error
View Answer
Answer: b
Explanation: None
advertisement
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. int main()
3. {
4. int x = 1;
5. if (x > 0)
6. printf("inside if\n");
7. else if (x > 0)
8. printf("inside elseif\n");
9. }
a) inside if
b) inside elseif
c)
inside if
inside elseif
1. #include <stdio.h>
2. int main()
3. {
4. int x = 0;
5. if (x++)
6. printf("true\n");
7. else if (x == 1)
8. printf("false\n");
9. }
a) true
b) false
c) compile time error
d) undefined behaviour
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int x = 0;
5. if (x == 1)
6. if (x == 0)
7. printf("inside if\n");
8. else
9. printf("inside else if\n");
10. else
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. int main()
3. {
4. int x = 0;
5. if (x == 0)
6. printf("true, ");
7. else if (x = 10)
8. printf("false, ");
9. printf("%d\n", x);
10. }
a) false, 0
b) true, 0
c) true, 10
d) compile time error
View Answer
Answer: b
Explanation: None.
5. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int x = 0;
5. if (x == 1)
6. if (x >= 0)
7. printf("true\n");
8. else
9. printf("false\n");
10. }
a) true
b) false
c) Depends on the compiler
d) No print statement
View Answer
Answer: d
Explanation: None.
6. The C statement “”if (a == 1 || b == 2) {}”” can be re-written as
___________
a)
Terminator21 C programming vrushabh
if (a == 1)
if (b == 2){}
b)
if (a == 1){}
if (b == 2){}
c)
if (a == 1){}
else if (b == 2){}
d) none of the mentioned
View Answer
Answer: d
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int a = 1;
5. if (a--)
6. printf("True");
7. if (a++)
8. printf("False");
9. }
a) True
b) False
c) True False
d) No Output
View Answer
Answer: a
Explanation: None.
9. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int a = 1;
5. if (a)
6. printf("All is Well ");
7. printf("I am Well\n");
8. else
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. int main()
3. {
4. if (printf("%d", printf(")))
5. printf("We are Happy");
6. else if (printf("1"))
7. printf("We are Sad");
8. }
a) 0We are Happy
b) 1We are Happy
c) 1We are Sad
d) compile time error
View Answer
Answer: d
Explanation: None.
1. What will be the output of the following C code? (Assuming that we have
entered the value 1 in the standard input)
advertisement
1. #include <stdio.h>
2. void main()
3. {
Terminator21 C programming vrushabh
4. double ch;
5. printf("enter a value between 1 to 2:");
6. scanf("%lf", &ch);
7. switch (ch)
8. {
9. case 1:
10. printf("1");
11. break;
12. case 2:
13. printf("2");
14. break;
15. }
16. }
a) Compile time error
b) 1
c) 2
d) Varies
View Answer
Answer: a
Explanation: None.
2. What will be the output of the following C code? (Assuming that we have
entered the value 1 in the standard input)
1. #include <stdio.h>
2. void main()
3. {
4. char *ch;
5. printf("enter a value between 1 to 3:");
6. scanf("%s", ch);
7. switch (ch)
8. {
9. case "1":
10. printf("1");
11. break;
12. case "2":
13. printf("2");
14. break;
15. }
16. }
a) 1
b) Compile time error
c) 2
d) Run time error
View Answer
Answer: b
Explanation: None.
advertisement
3. What will be the output of the following C code? (Assuming that we have
entered the value 1 in the standard input)
1. #include <stdio.h>
2. void main()
3. {
4. int ch;
Terminator21 C programming vrushabh
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int ch;
5. printf("enter a value between 1 to 2:");
6. scanf("%d", &ch);
7. switch (ch)
8. {
9. case 1:
10. printf("1\n");
11. break;
12. printf("hi");
13. default:
14. printf("2\n");
15. }
16. }
a) 1
b) hi 2
c) Run time error
d) 2
View Answer
Answer: d
Explanation: None.
5. What will be the output of the following C code? (Assuming that we have
entered the value 1 in the standard input)
1. #include <stdio.h>
2. void main()
3. {
4. int ch;
5. printf("enter a value between 1 to 2:");
6. scanf("%d", &ch);
7. switch (ch, ch + 1)
Terminator21 C programming vrushabh
8. {
9. case 1:
10. printf("1\n");
11. break;
12. case 2:
13. printf("2");
14. break;
15. }
16. }
a) 1
b) 2
c) 3
d) Run time error
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int a = 1, b = 1;
5. switch (a)
6. {
7. case a*b:
8. printf("yes ");
9. case a-b:
10. printf("no\n");
11. break;
12. }
13. }
a) yes
b) no
c) Compile time error
d) yes no
View Answer
Answer: c
Explanation: None.
7. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int x = 97;
5. switch (x)
6. {
7. case 'a':
8. printf("yes ");
9. break;
10. case 97:
11. printf("no\n");
12. break;
13. }
Terminator21 C programming vrushabh
14. }
a) yes
b) yes no
c) Duplicate case value error
d) Character case value error
View Answer
Answer: c
Explanation: None.
8. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. float f = 1;
5. switch (f)
6. {
7. case 1.0:
8. printf("yes\n");
9. break;
10. default:
11. printf("default\n");
12. }
13. }
a) yes
b) yes default
c) Undefined behaviour
d) Compile time error
View Answer
Answer: d
Explanation: None.
advertisement
1. #include <stdio.h>
2. const int a = 1, b = 2;
3. int main()
4. {
5. int x = 1;
6. switch (x)
7. {
Terminator21 C programming vrushabh
8. case a:
9. printf("yes ");
10. case b:
11. printf("no\n");
12. break;
13. }
14. }
a) yes no
b) yes
c) no
d) Compile time error
View Answer
Answer: d
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
2. #define max(a) a
3. int main()
4. {
5. int x = 1;
6. switch (x)
7. {
8. case max(2):
9. printf("yes\n");
10. case max(1):
11. printf("no\n");
12. break;
13. }
14. }
a) yes no
b) yes
c) no
d) Compile time error
View Answer
Answer: c
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. switch (printf("Do"))
5. {
6. case 1:
7. printf("First\n");
8. break;
9. case 2:
10. printf("Second\n");
11. break;
12. default:
13. printf("Default\n");
14. break;
Terminator21 C programming vrushabh
15. }
16. }
a) Do
b) DoFirst
c) DoSecond
d) DoDefault
View Answer
Answer: c
Explanation: None.
4. Comment on the output of the following C code.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int a = 1;
5. switch (a)
6. case 1:
7. printf("%d", a);
8. case 2:
9. printf("%d", a);
10. case 3:
11. printf("%d", a);
12. default:
13. printf("%d", a);
14. }
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
View Answer
Answer: d
Explanation: None.
5. Which datatype can accept the switch statement?
a) int
b) char
c) long
d) all of the mentioned
View Answer
Answer: d
Explanation: None.
6. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int a = 1;
5. switch (a)
6. {
7. case a:
8. printf("Case A ");
9. default:
Terminator21 C programming vrushabh
10. printf("Default");
11. }
12. }
a) Output: Case A
b) Output: Default
c) Output: Case A Default
d) Compile time error
View Answer
Answer: d
Explanation: None.
advertisement
1. #include <stdio.h>
2. switch (ch)
3. {
4. case 'a':
5. case 'A':
6. printf("true");
7. }
a) if (ch == ‘a’ && ch == ‘A’) printf(“true”);
b)
if (ch == 'a')
2. What will be the correct syntax for running two variable for loop
simultaneously?
a)
advertisement
for (i = 0; i < n;i++){}
for (j = 0; j < n;j += 5){}
d) none of the mentioned
View Answer
Answer: b
Explanation: None.
3. 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–)
View Answer
Answer: d
Explanation: None.
4. 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
View Answer
Answer: d
Explanation: None.
advertisement
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. int main()
3. {
4. short i;
5. for (i = 1; i >= 0; i++)
6. printf("%d\n", i);
7.
8. }
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
View Answer
Answer: c
Explanation: None.
6. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int k = 0;
5. for (k)
6. printf("Hello");
7. }
a) Compile time error
b) hello
c) Nothing
d) Varies
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int k = 0;
5. for (k < 3; k++)
6. printf("Hello");
7. }
a) Compile time error
b) Hello is printed thrice
c) Nothing
d) Varies
View Answer
Terminator21 C programming vrushabh
Answer: a
Explanation: None.
8. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. double k = 0;
5. for (k = 0.0; k < 3.0; k++)
6. printf("Hello");
7. }
a) Run time error
b) Hello is printed thrice
c) Hello is printed twice
d) Hello is printed infinitely
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. double k = 0;
5. for (k = 0.0; k < 3.0; k++);
6. printf("%lf", k);
7. }
a) 2.000000
b) 4.000000
c) 3.000000
d) Run time error
View Answer
Answer: c
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
Terminator21 C programming vrushabh
2. void main()
3. {
4. int k;
5. for (k = -3; k < -5; k++)
6. printf("Hello");
7. }
a) Hello
b) Infinite hello
c) Run time error
d) Nothing
View Answer
Answer: d
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. for (; ; ;)
6. printf("In for loop\n");
7. printf("After loop\n");
8. }
a) Compile time error
b) Infinite loop
c) After loop
d) Undefined behaviour
View Answer
Answer: a
Explanation: None.
4. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. for (i++; i == 1; i = 2)
6. prints("In for loop ");
7. printf("After loop\n");
8. }
a) In for loop after loop
b) After loop
c) Compile time error
d) Undefined behaviour
View Answer
Answer: a
Explanation: None.
5. What will be the output of the following C code?
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. for (foo(); i == 1; i = 2)
6. printf("In for loop\n");
7. printf("After loop\n");
8. }
9. int foo()
10. {
11. return 1;
12. }
a) After loop
b) In for loop after loop
c) Compile time error
d) Infinite loop
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int *p = NULL;
5. for (foo(); p; p = 0)
6. printf("In for loop\n");
7. printf("After loop\n");
8. }
a) In for loop after loop
b) Compile time error
c) Infinite loop
d) Depends on the value of NULL
View Answer
Answer: b
Explanation: None.
7. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. for (int i = 0;i < 1; i++)
5. printf("In for loop\n");
6. }
a) Compile time error
b) In for loop
c) Depends on the standard compiler implements
d) Depends on the compiler
View Answer
Answer: c
Explanation: None.
Terminator21 C programming vrushabh
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. while ()
5. printf("In while loop ");
6. printf("After loop\n");
7. }
a) In while loop after loop
b) After loop
c) Compile time error
d) Infinite loop
View Answer
Answer: c
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. do
5. printf("In while loop ");
6. while (0);
7. printf("After loop\n");
8. }
a) In while loop
b)
In while loop
after loop
Terminator21 C programming vrushabh
c) After loop
d) Infinite loop
View Answer
Answer: b
Explanation: None.
Join Sanfoundry@YouTube
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. do {
6. i++;
7. printf("In while loop\n");
8. } while (i < 3);
9. }
a)
In while loop
In while loop
In while loop
b)
In while loop
In while loop
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. do {
6. i++;
7. printf("in while loop\n");
8. } while (i < 3);
9. }
a) 2
b) 3
c) 4
Terminator21 C programming vrushabh
d) 1
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. while (i < 3)
6. i++;
7. printf("In while loop\n");
8. }
a) 2
b) 3
c) 4
d) 1
View Answer
Answer: c
Explanation: None.
6. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int i = 2;
5. do
6. {
7. printf("Hi");
8. } while (i < 2)
9. }
a) Compile time error
b) Hi Hi
c) Hi
d) Varies
View Answer
Answer: a
Explanation: None.
7. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int i = 0;
5. while (++i)
6. {
7. printf("H");
8. }
Terminator21 C programming vrushabh
9. }
a) H
b) H is printed infinite times
c) Compile time error
d) Varies
View Answer
Answer: b
Explanation: None.
8. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int i = 0;
5. do
6. {
7. printf("Hello");
8. } while (i != 0);
9. }
a) Nothing
b) H is printed infinite times
c) Hello
d) Run time error
View Answer
Answer: c
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. char *str = "";
5. do
6. {
7. printf("hello");
8. } while (str);
9. }
Terminator21 C programming vrushabh
a) Nothing
b) Run time error
c) Varies
d) Hello is printed infinite times
View Answer
Answer: d
Explanation: None.
2. What will be the output of the following C code?
1.#include <stdio.h>
2.void main()
3.{
4. int i = 0;
5. while (i < 10)
6. {
7. i++;
8. printf("hi\n");
9. while (i < 8)
10. {
11. i++;
12. printf("hello\n");
13. }
14. }
15. }
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
View Answer
Answer: d
Explanation: None.
advertisement
1.while (i < n)
2. i++;
3. ————-
4. do
5. i++;
6. while (i <= n);
a) n, n
b) n, n+1
Terminator21 C programming vrushabh
c) n+1, n
d) n+1, n+1
View Answer
Answer: d
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. while (i = 0)
6. printf("True\n");
7. printf("False\n");
8. }
a) True (infinite time)
b) True (1 time) False
c) False
d) Compiler dependent
View Answer
Answer: c
Explanation: None.
6. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0, j = 0;
5. while (i < 5, j < 10)
6. {
7. i++;
8. j++;
9. }
10. printf("%d, %d\n", i, j);
11. }
a) 5, 5
b) 5, 10
c) 10, 10
d) Syntax error
View Answer
Answer: c
Explanation: None.
advertisement
7. Which loop is most suitable to first perform the operation and then test the
condition?
a) for loop
b) while loop
c) do-while loop
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. int main()
3. {
4. int a = 0, i = 0, b;
5. for (i = 0;i < 5; i++)
6. {
7. a++;
8. continue;
9. }
10. }
a) 2
b) 3
c) 4
d) 5
View Answer
Answer: d
Explanation: None.
Terminator21 C programming vrushabh
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int a = 0, i = 0, b;
5. for (i = 0;i < 5; i++)
6. {
7. a++;
8. if (i == 3)
9. break;
10. }
11. }
a) 1
b) 2
c) 3
d) 4
View Answer
Answer: d
Explanation: None.
4. The keyword ‘break’ cannot be simply used within _________
a) do-while
b) if-else
c) for
d) while
View Answer
Answer: b
Explanation: None.
5. Which keyword is used to come out of a loop only for that iteration?
a) break
b) continue
c) return
d) none of the mentioned
View Answer
Answer: b
Explanation: None.
6. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int i = 0, j = 0;
5. for (i = 0;i < 5; i++)
6. {
7. for (j = 0;j < 4; j++)
8. {
9. if (i > 1)
10. break;
11. }
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. void main()
3. {
4. int i = 0;
5. int j = 0;
6. for (i = 0;i < 5; i++)
7. {
8. for (j = 0;j < 4; j++)
9. {
10. if (i > 1)
11. continue;
12. printf("Hi \n");
13. }
14. }
15. }
a) Hi is printed 9 times
b) Hi is printed 8 times
c) Hi is printed 7 times
d) Hi is printed 6 times
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int i = 0;
5. for (i = 0;i < 5; i++)
6. if (i < 4)
7. {
8. printf("Hello");
9. break;
10. }
11. }
a) Hello is printed 5 times
b) Hello is printed 4 times
c) Hello
d) Hello is printed 3 times
View Answer
Terminator21 C programming vrushabh
Answer: c
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int i = 0;
5. if (i == 0)
6. {
7. printf("Hello");
8. continue;
9. }
10. }
a) Hello is printed infinite times
b) Hello
c) Varies
d) Compile time error
View Answer
Answer: d
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int i = 0;
5. if (i == 0)
6. {
7. printf("Hello");
8. break;
9. }
10. }
a) Hello is printed infinite times
b) Hello
c) Varies
d) Compile time error
View Answer
Terminator21 C programming vrushabh
Answer: d
Explanation: None.
3. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. do
6. {
7. i++;
8. if (i == 2)
9. continue;
10. printf("In while loop ");
11. } while (i < 2);
12. printf("%d\n", i);
13. }
a) In while loop 2
b) In while loop in while loop 3
c) In while loop 3
d) Infinite loop
View Answer
Answer: a
Explanation: None.
4. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0, j = 0;
5. for (i; i < 2; i++){
6. for (j = 0; j < 3; j++)
7. {
8. printf("1\n");
9. break;
10. }
11. printf("2\n");
12. }
13. printf("after loop\n");
14. }
a)
1
2
after loop
b)
advertisement
1
after loop
c)
Terminator21 C programming vrushabh
1
2
1
2
after loop
d)
1
1
2
after loop
View Answer
Answer: c
Explanation: None.
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. while (i < 2)
6. {
7. if (i == 1)
8. break;
9. i++;
10. if (i == 1)
11. continue;
12. printf("In while loop\n");
13. }
14. printf("After loop\n");
15. }
a)
In while loop
After loop
advertisement
b) After loop
c)
In while loop
In while loop
After loop
Terminator21 C programming vrushabh
d) In while loop
View Answer
Answer: b
Explanation: None.
6. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. char c = 'a';
6. while (i < 2)
7. {
8. i++;
9. switch (c)
10. {
11. case 'a':
12. printf("%c ", c);
13. break;
14. break;
15. }
16. }
17. printf("after loop\n");
18. }
a) a after loop
b) a a after loop
c) after loop
d) error
View Answer
Answer: b
Explanation: None.
7. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. printf("before continue ");
5. continue;
6. printf("after continue\n");
7. }
a) Before continue after continue
b) Before continue
c) After continue
d) Compile time error
View Answer
Answer: d
Explanation: None.
Terminator21 C programming vrushabh
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. printf("%d ", 1);
5. goto l1;
6. printf("%d ", 2);
7. l1:goto l2;
8. printf("%d ", 3);
9. l2:printf("%d ", 4);
10. }
a) 1 4
b) Compilation error
c) 1 2 4
d) 1 3 4
View Answer
Answer: a
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. printf("%d ", 1);
5. l1:l2:
6. printf("%d ", 2);
7. printf("%d\n", 3);
8. }
a) Compilation error
b) 1 2 3
c) 1 2
d) 1 3
View Answer
Terminator21 C programming vrushabh
Answer: b
Explanation: None.
3. What will be the output of the following C code?
Join Sanfoundry@YouTube
1. #include <stdio.h>
2. int main()
3. {
4. printf("%d ", 1);
5. goto l1;
6. printf("%d ", 2);
7. }
8. void foo()
9. {
10. l1 : printf("3 ", 3);
11. }
a) 1 2 3
b) 1 3
c) 1 3 2
d) Compilation error
View Answer
Answer: d
Explanation: None.
4. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0, j = 0;
5. while (i < 2)
6. {
7. l1 : i++;
8. while (j < 3)
9. {
10. printf("Loop\n");
11. goto l1;
12. }
13. }
14. }
a) Loop Loop
b) Compilation error
c) Loop Loop Loop Loop
d) Infinite Loop
View Answer
Answer: d
Explanation: None.
5. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0, j = 0;
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0, j = 0;
5. l1: while (i < 2)
6. {
7. i++;
8. while (j < 3)
9. {
10. printf("loop\n");
11. goto l1;
12. }
13. }
14. }
a) loop loop
b) compilation error
c) oop loop loop loop
d) infinite loop
View Answer
Answer: a
Explanation: None.
7. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int i = 0;
5. if (i == 0)
6. {
7. goto label;
8. }
9. label: printf("Hello");
10. }
Terminator21 C programming vrushabh
a) Nothing
b) Error
c) Infinite Hello
d) Hello
View Answer
Answer: d
Explanation: None.
8. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int i = 0, k;
5. if (i == 0)
6. goto label;
7. for (k = 0;k < 3; k++)
8. {
9. printf("hi\n");
10. label: k = printf("%03d", i);
11. }
12. }
a) 0
b) hi hi hi 0 0 0
c) 0 hi hi hi 0 0 0
d) 0 0 0
View Answer
Answer: a
Explanation: None.
9. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int i = 0, k;
5. label: printf("%d", i);
6. if (i == 0)
7. goto label;
8. }
a) 0
b) Infinite 0
c) Nothing
d) Error
View Answer
Answer: b
Explanation: None.
Terminator21 C programming vrushabh
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int i = 5, k;
5. if (i == 0)
6. goto label;
7. label: printf("%d", i);
8. printf("Hey");
9. }
a) 5
b) Hey
c) 5 Hey
d) Nothing
View Answer
Answer: c
Explanation: None.
2. goto can be used to jump from main() to within a function.
a) true
b) false
c) depends
d) varies
View Answer
Answer: b
Explanation: None.
3. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. printf("%d ", 1);
5. goto l1;
6. printf("%d ", 2);
7. l1:goto l2;
8. printf("%d ", 3);
9. l2:printf("%d ", 4);
Terminator21 C programming vrushabh
10. }
a) 1 4
b) Compile time error
c) 1 2 4
d) 1 3 4
View Answer
Answer: a
Explanation: None.
4. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. printf("%d ", 1);
5. l1:l2:
6. printf("%d ", 2);
7. printf("%d\n", 3);
8. }
a) Compile time error
b) 1 2 3
c) 1 2
d) 1 3
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. printf("%d ", 1);
5. goto l1;
6. printf("%d ", 2);
7. }
8. void foo()
9. {
10. l1: printf("3 ", 3);
11. }
a) 1 2 3
b) 1 3
c) 1 3 2
d) Compile time error
View Answer
Answer: d
Explanation: None.
6. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
Terminator21 C programming vrushabh
4. int i = 0, j = 0;
5. while (i < 2)
6. {
7. l1: i++;
8. while (j < 3)
9. {
10. printf("loop\n");
11. goto l1;
12. }
13. }
14. }
a) loop loop
b) Compile time error
c) loop loop loop loop
d) Infinite loop
View Answer
Answer: d
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0, j = 0;
5. while (l1: i < 2)
6. {
7. i++;
8. while (j < 3)
9. {
10. printf("loop\n");
11. goto l1;
12. }
13. }
14. }
a) loop loop
b) Compile time error
c) loop loop loop loop
d) Infinite loop
View Answer
Answer: b
Explanation: None.
8. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0, j = 0;
5. l1: while (i < 2)
6. {
7. i++;
8. while (j < 3)
9. {
10. printf("loop\n");
Terminator21 C programming vrushabh
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. void foo();
5. printf("1 ");
6. foo();
7. }
8. void foo()
9. {
10. printf("2 ");
11. }
a) 1 2
b) Compile time error
c) 1 2 1 2
d) Depends on the compiler
View Answer
Answer: a
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. void foo(), f();
Terminator21 C programming vrushabh
5. f();
6. }
7. void foo()
8. {
9. printf("2 ");
10. }
11. void f()
12. {
13. printf("1 ");
14. foo();
15. }
a) Compile time error as foo is local to main
b) 1 2
c) 2 1
d) Compile time error due to declaration of functions inside main
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. void foo();
5. void f()
6. {
7. foo();
8. }
9. f();
10. }
11. void foo()
12. {
13. printf("2 ");
14. }
a) 2 2
b) 2
c) Compile time error
d) Depends on the compiler
View Answer
Answer: d
Explanation: Even though the answer is 2, this code will compile fine only
with gcc. GNU C supports nesting of functions in C as a language extension
whereas standard C compiler doesn’t.
4. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. void foo();
3. int main()
4. {
5. void foo();
6. foo();
Terminator21 C programming vrushabh
7. return 0;
8. }
9. void foo()
10. {
11. printf("2 ");
12. }
a) Compile time error
b) 2
c) Depends on the compiler
d) Depends on the standard
View Answer
Answer: b
Explanation: None.
5. What will be the output of the following C code?
1. #include <stdio.h>
2. void foo();
3. int main()
4. {
5. void foo(int);
6. foo(1);
7. return 0;
8. }
9. void foo(int i)
10. {
11. printf("2 ");
12. }
a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. void foo();
3. int main()
4. {
5. void foo(int);
6. foo();
7. return 0;
8. }
9. void foo()
10. {
11. printf("2 ");
12. }
a) 2
b) Compile time error
c) Depends on the compiler
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. void m()
3. {
4. printf("hi");
5. }
6. void main()
7. {
8. m();
9. }
a) hi
b) Run time error
c) Nothing
d) Varies
View Answer
Answer: a
Explanation: None.
8. What will be the output of the following C code?
1. #include <stdio.h>
2. void m();
3. void n()
4. {
5. m();
6. }
7. void main()
8. {
9. void m()
10. {
11. printf("hi");
12. }
13. }
a) hi
b) Compile time error
c) Nothing
d) Varies
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. m();
5. void m()
6. {
7. printf("hi");
8. }
9. }
a) hi
b) Compile time error
c) Nothing
d) Varies
View Answer
Answer: b
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. m();
5. }
6. void m()
7. {
8. printf("hi");
9. m();
10. }
a) Compile time error
b) hi
c) Infinite hi
d) Nothing
View Answer
Answer: c
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. static int x = 3;
5. x++;
6. if (x <= 5)
7. {
8. printf("hi");
9. main();
10. }
11. }
a) Run time error
b) hi
c) Infinite hi
d) hi hi
View Answer
Answer: d
Explanation: None.
4. Which of the following is a correct format for declaration of function?
a) return-type function-name(argument type);
b) return-type function-name(argument type){}
c) return-type (argument type)function-name;
d) all of the mentioned
View Answer
Answer: a
Explanation: None.
advertisement
advertisement
int sum(a, b)
return (a + b);
Terminator21 C programming vrushabh
double func();
int main(){}
double func(){}
b)
double func(){};
int main(){}
c)
int main()
{
double func();
}
double func(){//statements}
d) None of the mentioned
View Answer
Answer: d
Explanation: None.
advertisement
3. What will be the output of the following C code having void return-type
function?
1. #include <stdio.h>
2. void foo()
3. {
4. return 1;
5. }
6. void main()
7. {
8. int x = 0;
9. x = foo();
10. printf("%d", x);
11. }
a) 1
b) 0
c) Runtime error
d) Compile time error
View Answer
Answer: d
Explanation: None.
4. What will be the data type returned for the following C function?
1. #include <stdio.h>
2. int func()
3. {
4. return (double)(char)5.0;
5. }
a) char
b) int
c) double
d) multiple type-casting in return is illegal
View Answer
Terminator21 C programming vrushabh
Answer: b
Explanation: None.
advertisement
int func(int);
double func(int);
int func(float);
a) A function with same name cannot have different signatures
b) A function with same name cannot have different return types
c) A function with same name cannot have different number of parameters
d) All of the mentioned
View Answer
Answer: d
Explanation: None.
6. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int k = m();
5. printf("%d", k);
6. }
7. void m()
8. {
9. printf("hello");
10. }
a) hello 5
b) Error
c) Nothing
d) Junk value
View Answer
Answer: a
Explanation: None.
7. What will be the output of the following C code?
1. #include <stdio.h>
2. int *m()
3. {
4. int *p = 5;
5. return p;
6. }
7. void main()
8. {
9. int *k = m();
10. printf("%d", k);
11. }
a) 5
b) Junk value
c) 0
Terminator21 C programming vrushabh
d) Error
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. int *m();
3. void main()
4. {
5. int *k = m();
6. printf("hello ");
7. printf("%d", k[0]);
8. }
9. int *m()
10. {
11. int a[2] = {5, 8};
12. return a;
13. }
a) hello 5 8
b) hello 5
c) hello followed by garbage value
d) Compilation error
View Answer
Answer: c
Explanation: None.
advertisement
1. #include <stdio.h>
2. int *m();
3. void main()
4. {
5. int k = m();
6. printf("%d", k);
7. }
8. int *m()
9. {
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. void m(int k)
3. {
4. printf("hi");
5. }
6. void m(double k)
7. {
8. printf("hello");
9. }
10. void main()
11. {
12. m(3);
13. }
a) hi
b) hello
c) Compile time error
d) Nothing
View Answer
Answer: c
Explanation: None.
advertisement
1. #include <stdio.h>
2. int foo();
3. int main()
4. {
5. int i = foo();
6. }
7. foo()
8. {
9. printf("2 ");
Terminator21 C programming vrushabh
10. return 2;
11. }
a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. double foo();
3. int main()
4. {
5. foo();
6. return 0;
7. }
8. foo()
9. {
10. printf("2 ");
11. return 2;
12. }
a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard
View Answer
Answer: b
Explanation: None.
6. Functions can return structure in C?
a) True
b) False
c) Depends on the compiler
d) Depends on the standard
View Answer
Answer: a
Explanation: None.
7. Functions can return enumeration constants in C?
a) true
b) false
c) depends on the compiler
d) depends on the standard
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. enum m{JAN, FEB, MAR};
3. enum m foo();
4. int main()
5. {
6. enum m i = foo();
7. printf("%d\n", i);
8. }
9. int foo()
10. {
11. return JAN;
12. }
a) Compile time error
b) 0
c) Depends on the compiler
d) Depends on the standard
View
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. m();
5. printf("%d", x);
6. }
7. int x;
8. void m()
9. {
10. x = 4;
11. }
a) 4
b) Compile time error
c) 0
Terminator21 C programming vrushabh
d) Undefined
View Answer
Answer: b
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
2. int x;
3. void main()
4. {
5. printf("%d", x);
6. }
a) Junk value
b) Run time error
c) 0
d) Undefined
View Answer
Answer: c
Explanation: None.
Join Sanfoundry@YouTube
1. #include <stdio.h>
2. int x = 5;
3. void main()
4. {
5. int x = 3;
6. printf("%d", x);
7. {
8. x = 4;
9. }
10. printf("%d", x);
11. }
a) Run time error
b) 3 3
c) 3 5
d) 3 4
View Answer
Answer: d
Explanation: None.
4. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. int x = 5;
3. void main()
4. {
5. int x = 3;
6. printf("%d", x);
7. {
8. int x = 4;
Terminator21 C programming vrushabh
9. }
10. printf("%d", x);
11. }
a) 3 3
b) 3 4
c) 3 5
d) Run time error
View Answer
Answer: a
Explanation: None.
5. Functions in C are always _________
a) Internal
b) External
c) Both Internal and External
d) External and Internal are not valid terms for functions
View Answer
Answer: b
Explanation: None.
6. Global variables are ____________
a) Internal
b) External
c) Both Internal and External
d) None of the mentioned
View Answer
Answer: b
Explanation: None.
7. Which of the following is an external variable in the following C code?
advertisement
1. #include <stdio.h>
2. int func (int a)
3. {
4. int b;
5. return b;
6. }
7. int main()
8. {
9. int c;
10. func (c);
11. }
12. int d;
a) a
b) b
c) c
d) d
View Answer
Answer: d
Explanation: None.
8. What will be the output of the following C code?
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. int main()
3. {
4. printf("%d", d++);
5. }
6. int d = 10;
a) 9
b) 10
c) 11
d) Compile time error
View Answer
Answer: d
Explanation: None.
9. What will be the output of the following C code?
1. #include <stdio.h>
2. double var = 8;
3. int main()
4. {
5. int var = 5;
6. printf("%d", var);
7. }
a) 5
b) 8
c) Compile time error due to wrong format identifier for double
d) Compile time error due to redeclaration of variable with same name
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. double i;
3. int main()
4. {
5. printf("%g\n",i);
6. return 0;
7. }
Terminator21 C programming vrushabh
a) 0
b) 0.000000
c) Garbage value
d) Depends on the compiler
View Answer
Answer: a
Explanation: None.
2. Which part of the program address space is p stored in the following C
code?
1. #include <stdio.h>
2. int *p = NULL;
3. int main()
4. {
5. int i = 0;
6. p = &i;
7. return 0;
8. }
a) Code/text segment
b) Data segment
c) Bss segment
d) Stack
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. int *p;
3. int main()
4. {
5. int i = 0;
6. p = &i;
7. return 0;
8. }
a) Code/text segment
b) Data segment
c) Bss segment
d) Stack
View Answer
Answer: c
Explanation: None.
4. Can variable i be accessed by functions in another source file?
advertisement
1. #include <stdio.h>
2. int i;
3. int main()
Terminator21 C programming vrushabh
4. {
5. printf("%d\n", i);
6. }
a) Yes
b) No
c) Only if static keyword is used
d) Depends on the type of the variable
View Answer
Answer: a
Explanation: None.
5. Property of the external variable to be accessed by any source file is called
by the C90 standard as __________
a) external linkage
b) external scope
c) global scope
d) global linkage
View Answer
Answer: a
Explanation: None.
6. What will be the output of the following C code?
1. #include <stdio.h>
2. int *i;
3. int main()
4. {
5. if (i == NULL)
6. printf("true\n");
7. return 0;
8. }
a) true
b) true only if NULL value is 0
c) Compile time error
d) Nothing
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. int *i;
3. int main()
4. {
5. if (i == 0)
6. printf("true\n");
7. return 0;
8. }
a) true
b) true only if NULL value is 0
c) Compile time error
Terminator21 C programming vrushabh
d) Nothing
View Answer
Answer: b
Explanation: None.
8. What will be the output of the following C code?
1. #include <stdio.h>
2. static int x = 5;
3. void main()
4. {
5. x = 9;
6. {
7. int x = 4;
8. }
9. printf("%d", x);
10. }
a) 9
b) 4
c) 5
d) 0
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. int i;
3. int main()
4. {
5. extern int i;
6. if (i == 0)
7. printf("scope rules\n");
8. }
Terminator21 C programming vrushabh
a) scope rules
b) Compile time error due to multiple declaration
c) Compile time error due to not defining type in statement extern i
d) Nothing will be printed as value of i is not zero because i is an automatic
variable
View Answer
Answer: a
Explanation: None.
2. What will be the output of the following C code (without linking the source
file in which ary1 is defined)?
1. #include <stdio.h>
2. int main()
3. {
4. extern ary1[];
5. printf("scope rules\n");
6. }
a) scope rules
b) Linking error due to undefined reference
c) Compile time error because size of array is not provided
d) Compile time error because datatype of array is not provided
View Answer
Answer: a
Explanation: None.
advertisement
3. What will be the output of the following C code (after linking to source file
having definition of ary1)?
1. #include <stdio.h>
2. int main()
3. {
4. extern ary1[];
5. printf("%d\n", ary1[0]);
6. }
a) Value of ary1[0];
b) Compile time error due to multiple definition
c) Compile time error because size of array is not provided
d) Compile time error because datatype of array is not provided
View Answer
Answer: d
Explanation: None.
4. What is the scope of an external variable?
a) Whole source file in which it is defined
b) From the point of declaration to the end of the file in which it is defined
c) Any source file in a program
d) From the point of declaration to the end of the file being compiled
View Answer
Answer: d
Explanation: None.
Terminator21 C programming vrushabh
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int i;
5. for (i = 0;i < 5; i++)
6. int a = i;
7. printf("%d", a);
8. }
a) a is out of scope when printf is called
b) Redeclaration of a in same scope throws error
c) Syntax error in declaration of a
d) No errors, program will show the output 5
View Answer
Answer: c
Explanation: None.
7. Which variable has the longest scope in the following C code?
advertisement
1. #include <stdio.h>
2. int b;
3. int main()
4. {
5. int c;
6. return 0;
7. }
8. int a;
a) a
b) b
c) c
d) Both a and b
View Answer
Answer: b
Explanation: None.
8. Comment on the following 2 C programs.
5. int b;
6. int c;
7. }
8.
9. #include <stdio.h> //Program 2
10. int main()
11. {
12. int a;
13. {
14. int b;
15. }
16. {
17. int c;
18. }
19. }
a) Both are same
b) Scope of c is till the end of the main function in Program 2
c) In Program 1, variables a, b and c can be used anywhere in the main
function whereas in Program 2, variables b and c can be used only inside
their respective blocks
d) None of the mentioned
View Answer
Answer: c
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int a;
5. {
6. int b;
7. }
8. }
Terminator21 C programming vrushabh
a) a->b, a->b
b) a->b, b->a
c) b->a, a->b
d) b->a, b->a
View Answer
Answer: b
Explanation: None.
2. Array sizes are optional during array declaration by using ______ keyword.
a) auto
b) static
c) extern
d) register
View Answer
Answer: c
Explanation: None.
3. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. int x = 3;
5. {
6. x = 4;
7. printf("%d", x);
8. }
9. }
a) 4
b) 3
c) 0
d) Undefined
View Answer
Answer: a
Explanation: None.
4. What will be the output of the following C code?
1. #include <stdio.h>
2. int x = 5;
3. void main()
4. {
5. int x = 3;
6. m();
7. printf("%d", x);
8. }
9. void m()
10. {
11. x = 8;
12. n();
13. }
14. void n()
15. {
16. printf("%d", x);
Terminator21 C programming vrushabh
17. }
a) 8 3
b) 3 8
c) 8 5
d) 5 3
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. int x;
3. void main()
4. {
5. m();
6. printf("%d", x);
7. }
8. void m()
9. {
10. x = 4;
11. }
a) 0
b) 4
c) Compile time error
d) Undefined
View Answer
Answer: b
Explanation: None.
6. What will be the output of the following C code?
1. #include <stdio.h>
2. static int x = 5;
3. void main()
4. {
5. int x = 9;
6. {
7. x = 4;
8. }
9. printf("%d", x);
10. }
a) 9
b) 5
c) 4
d) 0
View Answer
Answer: c
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. {
5. int x = 8;
6. }
7. printf("%d", x);
8. }
a) 8
b) 0
c) Undefined
d) Compile time error
View Answer
Answer: d
Explanation: None.
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. m();
5. m();
6. }
7. void m()
8. {
9. static int x = 5;
10. x++;
11. printf("%d", x);
12. }
a) 6 7
b) 6 6
c) 5 5
d) 5 6
View Answer
Answer: a
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
Terminator21 C programming vrushabh
2. void main()
3. {
4. static int x;
5. printf("x is %d", x);
6. }
a) 0
b) 1
c) Junk value
d) Run time error
View Answer
Answer: a
Explanation: None.
Join Sanfoundry@YouTube
1. #include <stdio.h>
2. static int x;
3. void main()
4. {
5. int x;
6. printf("x is %d", x);
7. }
a) 0
b) Junkvalue
c) Run time error
d) Nothing
View Answer
Answer: b
Explanation: None.
4. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. static double x;
5. int x;
6. printf("x is %d", x);
7. }
a) Nothing
b) 0
c) Compile time error
d) Junkvalue
View Answer
Answer: c
Explanation: None.
5. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
Terminator21 C programming vrushabh
3. {
4. static int x;
5. if (x++ < 2)
6. main();
7. }
a) Infinite calls to main
b) Run time error
c) Varies
d) main is called twice
View Answer
Answer: d
Explanation: None.
advertisement
1. What will be the output of the following C code if these two files namely
test.c and test1.c are linked and run?
advertisement
1. -------file test.c-------
2. #include <stdio.h>
3. #include ""test.h""
4. int main()
Terminator21 C programming vrushabh
5. {
6. i = 10;
7. printf(""%d "", i);
8. foo();
9. }
10.
11. -----file test1.c------
12. #include <stdio.h>
13. #include ""test.h""
14. int foo()
15. {
16. printf(""%d\n"", i);
17. }
18.
19. -----file test.h-----
20. #include <stdio.h>
21. #include <stdlib.h>
22. static int i;
a) 10 0
b) 0 0
c) 10 10
d) Compilation Error
View Answer
Answer: a
Explanation: None.
2. Functions have static qualifier for its declaration by default.
a) True
b) False
c) Depends on the compiler
d) Depends on the standard
View Answer
Answer: b
Explanation: None.
3. Is initialisation mandatory for local static variables?
a) Yes
b) No
c) Depends on the compiler
d) Depends on the standard
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. foo();
5. foo();
6. }
7. void foo()
8. {
Terminator21 C programming vrushabh
9. int i = 11;
10. printf("%d ", i);
11. static int j = 12;
12. j = j + 1;
13. printf("%d\n", j);
14. }
a) 11 12 11 12
b) 11 13 11 14
c) 11 12 11 13
d) Compile time error
View Answer
Answer: b
Explanation: None.
5. Assignment statements assigning value to local static variables are
executed only once.
a) True
b) False
c) Depends on the code
d) None of the mentioned
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. void func();
3. int main()
4. {
5. static int b = 20;
6. func();
7. }
8. void func()
9. {
Terminator21 C programming vrushabh
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. register int i = 10;
5. int *p = &i;
6. *p = 11;
7. printf("%d %d\n", i, *p);
8. }
a) Depends on whether i is actually stored in machine register
b) 10 10
c) 11 11
d) Compile time error
View Answer
2. register keyword mandates compiler to place it in machine register.
a) True
b) False
c) Depends on the standard
d) None of the mentioned
View Answer
Answer: b
Explanation: None.
Terminator21 C programming vrushabh
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. register static int i = 10;
5. i = 11;
6. printf("%d\n", i);
7. }
a) 10
b) Compile time error
c) Undefined behaviour
d) 11
View Answer
Answer: b
Explanation: None.
4. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. register auto int i = 10;
5. i = 11;
6. printf("%d\n", i);
7. }
a) 10
b) Compile time error
c) Undefined behaviour
d) 11
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. register const int i = 10;
5. i = 11;
6. printf("%d\n", i);
7. }
a) 10
b) Compile time error
c) Undefined behaviour
d) 11
View Answer
Answer: b
Explanation: None.
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. void main()
3. {
4. register int x = 5;
5. m();
6. printf("x is %d", x);
7. }
8. void m()
9. {
10. x++;
11. }
a) 6
b) 5
c) Junk value
d) Compile time error
View Answer
Answer: d
Explanation: None.
1. #include <stdio.h>
Terminator21 C programming vrushabh
2. void main()
3. {
4. register int x = 0;
5. if (x < 2)
6. {
7. x++;
8. main();
9. }
10. }
a) Segmentation fault
b) main is called twice
c) main is called once
d) main is called thrice
View Answer
Answer: a
Explanation: None.
7. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. register int x;
5. printf("%d", x);
6. }
a) 0
b) Junk value
c) Compile time error
d) Nothing
View Answer
Answer: b
Explanation: None.
8. What will be the output of the following C code?
1. #include <stdio.h>
2. register int x;
3. void main()
4. {
5. printf("%d", x);
6. }
a) Varies
b) 0
c) Junk value
d) Compile time error
View Answer
Answer: d
Explanation: None.
Terminator21 C programming vrushabh
Join Sanfoundry@YouTube
Terminator21 C programming vrushabh
1.#include <stdio.h>
2.#define foo(m, n) m * n = 10
3.int main()
4.{
5. printf("in main\n");
6.}
a) In main
b) Compilation error as lvalue is required for the expression m*n=10
c) Preprocessor error as lvalue is required for the expression m*n=10
d) None of the mentioned
View Answer
Answer: a
Explanation: Preprocessor just replaces whatever is given compiler then
checks for error at the replaced part of the code. Here it is not replaced
anywhere.
Output:
$ cc pgm1.c
$ a.out
in main
5. C preprocessor is conceptually the first step during compilation.
a) True
b) False
c) Depends on the compiler
d) Depends on the standard
View Answer
Answer: a
Explanation: None.
advertisement
another program
b) That is nothing but a loader
c) That links various source files
d) All of the mentioned
View Answer
Answer: a
Explanation: A preprocessor is a program that processes its input data to
produce output that is used as input to another program.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int one = 1, two = 2;
5. #ifdef next
6. one = 2;
7. two = 1;
8. #endif
9. printf("%d, %d", one, two);
10. }
a) 1, 1
b) 1, 2
c) 2, 1
d) 2, 2
View Answer
Answer: b
Explanation: None.
5. The C-preprocessors are specified with _________symbol.
a) #
b) $
c) ” ”
d) &
View Answer
Answer: a
Explanation: The C-preprocessors are specified with # symbol.
advertisement
advertisement
1. #include <stdio.h>
2. #define SYSTEM 20
3. int main()
4. {
5. int a = 20;
6. #if SYSTEM == a
7. printf("HELLO ");
8. #endif
9. #if SYSTEM == 20
10. printf("WORLD\n");
11. #endif
12. }
a) HELLO
b) WORLD
c) HELLO WORLD
d) No Output
View Answer
Answer: b
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
2. #define Cprog
3. int main()
4. {
5. int a = 2;
6. #ifdef Cprog
Terminator21 C programming vrushabh
7. a = 1;
8. printf("%d", Cprog);
9. }
a) No output on execution
b) Output as 1
c) Output as 2
d) Compile time error
View Answer
Answer: d
Explanation: None.
Join Sanfoundry@YouTube
1. #include <stdio.h>
2. #define COLD
3. int main()
4. {
5. #ifdef COLD
6. printf("COLD\t");
7. #undef COLD
8. #endif
9. #ifdef COLD
10. printf("HOT\t");
11. #endif
12. }
a) HOT
b) COLD
c) COLD HOT
d) No Output
View Answer
Answer: b
Explanation: None.
advertisement
#if
#else
#endif
b)
#if
Terminator21 C programming vrushabh
#elif
#endif
c)
advertisement
#if
#if
#endif
d)
#if
#undef
#endif
View Answer
Answer: c
Explanation: None.
1. #include <stdio.h>
2. #define MIN 0
3. #if MIN
4. #define MAX 10
5. #endif
6. int main()
7. {
8. printf("%d %d\n", MAX, MIN);
9. return 0;
10. }
a) 10 0
b) Compile time error
c) Undefined behaviour
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. #define MIN 0
3. #ifdef MIN
4. #define MAX 10
5. #endif
6. int main()
7. {
8. printf("%d %d\n", MAX, MIN);
9. return 0;
10. }
a) 10 0
b) Compile time error
c) Undefined behaviour
d) None of the mentioned
View Answer
Answer: a
Explanation: None.
5. What will be the output of the following C code?
1. #include <stdio.h>
2. #define MIN 0
3. #if defined(MIN) + defined(MAX)
4. #define MAX 10
5. #endif
6. int main()
7. {
8. printf("%d %d\n", MAX, MIN);
9. return 0;
10. }
a) 10 0
b) Compile time error
c) Undefined behaviour
d) Somegarbagevalue 0
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. #define MIN 0
3. #if defined(MIN) - (!defined(MAX))
4. #define MAX 10
5. #endif
Terminator21 C programming vrushabh
6. int main()
7. {
8. printf("%d %d\n", MAX, MIN);
9. return 0;
10. }
a) 10 0
b) Compile time error
c) Undefined behaviour
d) Somegarbagevalue 0
View Answer
Answer: b
Explanation: None.
7. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. #define MIN 0
3. #ifdef(MIN)
4. #define MAX 10
5. #endif
6. int main()
7. {
8. printf("%d %d\n", MAX, MIN);
9. return 0;
10. }
a) 10 0
b) Compile time error
c) Run time error
d) Preprocessor error
View Answer
Answer: d
Explanation: None.
8. What will be the output of the following C code?
1. #include <stdio.h>
2. #define MIN 0);
3. #ifdef MIN
4. #define MAX 10
5. #endif
6. int main()
7. {
8. printf("%d %d\n", MAX, MIN
9. return 0;
10. }
a) 10 0
b) Compile time error due to illegal syntax for printf
c) Undefined behaviour
d) Compile time error due to illegal MIN value
View Answer
Answer: a
Explanation: None.
Terminator21 C programming vrushabh
c) typedef
d) all of the mentioned
View Answer
Answer: d
Explanation: None.
3. Which operator connects the structure name to its member name?
a) –
b) <-
c) .
d) Both <- and .
View Answer
Answer: c
Explanation: None.
4. Which of the following cannot be a structure member?
a) Another structure
b) Function
c) Array
d) None of the mentioned
View Answer
Answer: b
Explanation: None.
5. Which of the following structure declaration will throw an error?
a)
struct temp{}s;
main(){}
b)
advertisement
struct temp{};
struct temp s;
main(){}
c)
struct temp s;
struct temp{};
main(){}
d) None of the mentioned
View Answer
Answer: d
Explanation: None.
6. What will be the output of the following C code?
1. #include <stdio.h>
2. struct student
3. {
4. int no;
5. char name[20];
Terminator21 C programming vrushabh
6. }
7. void main()
8. {
9. struct student s;
10. s.no = 8;
11. printf("hello");
12. }
a) Compile time error
b) Nothing
c) hello
d) Varies
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. struct student
3. {
4. int no = 5;
5. char name[20];
6. };
7. void main()
8. {
9. struct student s;
10. s.no = 8;
11. printf("hello");
12. }
a) Nothing
b) Compile time error
c) hello
d) Varies
View Answer
Answer: b
Explanation: None.
8. What will be the output of the following C code?
1. #include <stdio.h>
2. struct student
3. {
4. int no;
5. char name[20];
6. };
7. void main()
8. {
9. student s;
10. s.no = 8;
11. printf("hello");
12. }
a) Nothing
b) hello
c) Compile time error
Terminator21 C programming vrushabh
d) Varies
View Answer
Answer: c
Explanation: None.
9. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. struct student
5. {
6. int no;
7. char name[20];
8. };
9. struct student s;
10. s.no = 8;
11. printf("%d", s.no);
12. }
a) Nothing
b) Compile time error
c) Junk
d) 8
View Answer
Answer: d
Explanation: None.
advertisement
1. #include <stdio.h>
2. struct p
3. {
4. int k;
5. char c;
6. float f;
7. };
8. int main()
9. {
10. struct p x = {.c = 97, .f = 3, .k = 1};
11. printf("%f\n", x.f);
12. }
a) Yes
b) No
c) Depends on the standard
d) Depends on the platform
View Answer
Answer: c
Explanation: None.
Terminator21 C programming vrushabh
advertisement
1. #include <stdio.h>
2. void main()
3. {
4. struct student
5. {
6. int no;
7. char name[20];
8. };
9. struct student s;
10. no = 8;
11. printf("%d", no);
12. }
a) Nothing
b) Compile time error
c) Junk
d) 8
View Answer
Answer: b
Explanation: None.
2. How many bytes in memory taken by the following C structure?
1. #include <stdio.h>
2. struct test
3. {
4. int k;
5. char c;
6. };
a) Multiple of integer size
b) integer size+character size
c) Depends on the platform
d) Multiple of word size
View Answer
Answer: a
Explanation: None.
3. What will be the output of the following C code?
Terminator21 C programming vrushabh
Join Sanfoundry@YouTube
1. #include <stdio.h>
2. struct
3. {
4. int k;
5. char c;
6. };
7. int main()
8. {
9. struct p;
10. p.k = 10;
11. printf("%d\n", p.k);
12. }
a) Compile time error
b) 10
c) Undefined behaviour
d) Segmentation fault
View Answer
Answer: a
Explanation: None.
4. What will be the output of the following C code?
1. #include <stdio.h>
2. struct
3. {
4. int k;
5. char c;
6. } p;
7. int p = 10;
8. int main()
9. {
10. p.k = 10;
11. printf("%d %d\n", p.k, p);
12. }
a) Compile time error
b) 10 10
c) Depends on the standard
d) Depends on the compiler
View Answer
Answer: a
Explanation: None.
5. What will be the output of the following C code?
1. #include <stdio.h>
2. struct p
3. {
4. int k;
5. char c;
6. };
7. int p = 10;
8. int main()
9. {
10. struct p x;
11. x.k = 10;
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. struct p
3. {
4. int k;
5. char c;
6. float f;
7. };
8. int p = 10;
9. int main()
10. {
11. struct p x = {1, 97};
12. printf("%f %d\n", x.f, p);
13. }
a) Compile time error
b) 0.000000 10
c) Somegarbage value 10
d) 0 10
View Answer
Answer: b
Explanation: None.
7. What will be the output of the following C code according to C99 standard?
1. #include <stdio.h>
2. struct p
3. {
4. int k;
5. char c;
6. float f;
7. };
8. int main()
9. {
10. struct p x = {.c = 97, .f = 3, .k = 1};
11. printf("%f\n", x.f);
12. }
a) 3.000000
b) Compile time error
c) Undefined behaviour
d) 1.000000
View Answer
Answer: a
Explanation: None.
Terminator21 C programming vrushabh
8. What will be the output of the following C code according to C99 standard?
advertisement
1. #include <stdio.h>
2. struct p
3. {
4. int k;
5. char c;
6. float f;
7. };
8. int main()
9. {
10. struct p x = {.c = 97, .k = 1, 3};
11. printf("%f \n", x.f);
12. }
a) 3.000000
b) 0.000000
c) Compile time error
d) Undefined behaviour
View Answer
Answer: b
Explanation: None.
9. What will be the output of the following C code according to C99 standard?
1. #include <stdio.h>
2. struct p
3. {
4. int k;
5. char c;
6. float f;
7. };
8. int main()
9. {
10. struct p x = {.c = 97};
11. printf("%f\n", x.f);
12. }
a) 0.000000
b) Somegarbagevalue
c) Compile time error
d) None of the mentioned
View Answer
Answer: a
Explanation: None.
Terminator21 C programming vrushabh
prog1|prog2
a) It runs prog1 first, prog2 second
b) It runs prog2 first, prog1 second
c) It runs both the programs, pipes output of prog1 to input of prog2
d) It runs both the programs, pipes output of prog2 to input of prog1
View Answer
Answer: c
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. char c = '�';
5. putchar(c);
6. }
a) Compile time error
b) Nothing
c) 0
d) Undefined behaviour
View Answer
Answer: b
Explanation: None.
3. putchar(c) function/macro always outputs character c to the __________
a) screen
b) standard output
c) depends on the compiler
d) depends on the standard
View Answer
Answer: b
Explanation: None.
advertisement
4. What will be the output of the following C code if following commands are
used to run (considering myfile exists)?
d) Undefined behaviour
View Answer
Answer: c
Explanation: None.
5. What will be the output of the following C code if following commands are
used to run (considering myfile exists)?
advertisement
1. gcc -otest test.c
2. ./test > myfile
3.
4. #include <stdio.h>
5. int main(int argc, char **argv)
6. {
7. char c = 'd';
8. putchar(c);
9. printf(" %d\n", argc);
10. }
a) d 2 in myfile
b) d 1 in myfile
c) d in myfile and 1 in screen
d) d in myfile and 2 in screen
View Answer
Answer: b
Explanation: None.
6. What will be the output of the following C code if following commands are
used to run and if myfile does not exist?
d) nothing
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int i = 10, j = 2;
5. printf("%d\n", printf("%d %d ", i, j));
6. }
a) Compile time error
b) 10 2 4
c) 10 2 2
d) 10 2 5
View Answer
Answer: d
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 10, j = 3;
5. printf("%d %d %d", i, j);
6. }
a) Compile time error
b) 10 3
c) 10 3 some garbage value
d) Undefined behaviour
View Answer
Terminator21 C programming vrushabh
Answer: c
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int i = 10, j = 3, k = 3;
5. printf("%d %d ", i, j, k);
6. }
a) Compile time error
b) 10 3 3
c) 10 3
d) 10 3 somegarbage value
View Answer
Answer: c
Explanation: None.
4. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. char *s = "myworld";
5. int i = 9;
6. printf("%*s", i, s);
7. }
a) myworld
b) myworld(note: spaces to the left of myworld)
c) myworld (note:followed by two spaces after myworld)
d) Undefined
View Answer
Answer: b
Explanation: None.
5. What will be the output of the following C code?
1. #include <stdio.h>
2. int main(int argc, char** argv)
3. {
4. char *s = "myworld";
5. int i = 3;
6. printf("%10.*s", i, s);
7. }
a) myw(note:7 spaces before myw)
b) myworld(note:2 spaces before myworld)
c) myworld (note:2 spaces after myworld)
d) myw(note:6 spaces after myw)
View Answer
Terminator21 C programming vrushabh
Answer: a
Explanation: In the format represented by “%10.*s”, the width of the string
will be 10 spaces which is aligned to the right, by default. Since we have
asterisk (*) after the precision dot (.), the value of precision will be the value
stored in the variable i. The value of i is 3, so this signifies max length of the
string as 3 characters. So, the final formatted output will be a 10 character
output with 3 characters “myw” printed with right alignment and the 1st 7
characters will be simply space characters.
advertisement
printf(“%10s”, state);
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int i = 10, j = 2;
5. printf("%d\n", printf("%d %d ", i, j));
6. }
a) Compile time error
b) 10 2 4
c) 10 2 2
d) 10 2 5
View Answer
Answer: d
Explanation: None.
advertisement
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. int main()
3. {
4. int i = 10, j = 3;
5. printf("%d %d %d", i, j);
6. }
a) Compile time error
b) 10 3
c) 10 3 some garbage value
d) Undefined behaviour
View Answer
Answer: c
Explanation: None.
5. What will be the output of the following C code?
advertisement
1. #include <stdio.h>
2. int main()
3. {
4. int i = 10, j = 3, k = 3;
5. printf("%d %d ", i, j, k);
6. }
a) Compile time error
b) 10 3 3
c) 10 3
d) 10 3 somegarbage value
View Answer
Answer: c
Explanation: None.
6. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. char *s = "myworld";
5. int i = 9;
6. printf("%*s", i, s);
7. }
a) myworld
b) myworld(note: spaces to the left of myworld)
c) myworld (note:followed by two spaces after myworld)
d) Undefined
View Answer
Answer: b
Explanation: None.
advertisement
1. #include <stdio.h>
2. int main(int argc, char **argv)
3. {
4. char *s = "myworld";
5. int i = 3;
6. printf("%10.*s", i, s);
7. }
a) myw(note:7 spaces before myw)
b) myworld(note:2 spaces before myworld)
c) myworld (note:2 spaces after myworld)
d) myw(note:6 spaces after myworld)
View Answer
Answer: a
Explanation: In the format represented by “%10.*s”, the width of the string
will be 10 spaces which is aligned to the right, by default. Since we have
asterisk (*) after the precision dot (.), the value of precision will be the value
stored in the variable i. The value of i is 3, so this signifies max length of the
string as 3 characters. So, the final formatted output will be a 10 character
output with 3 characters “myw” printed with right alignment and the 1st 7
characters will be simply space characters.
8. What is the difference between %e and %g?
a) %e output formatting depends on the argument and %g always formats in
the format [-]m.dddddd or [-]m.dddddE[+|-]xx where no.of ds are optional
b) %e always formats in the format [-]m.dddddd or [-]m.dddddE[+|-]xx where
no.of ds are optional and output formatting depends on the argument
c) No differences
d) Depends on the standard
View Answer
Answer: b
Explanation: None.
1. How many digits are present after the decimal in float value?
a) 1
b) 3
c) 6
d) 16
View Answer
Answer: c
Explanation: None.
advertisement
Answer: d
Explanation: None.
6. In the following C code, the union size is decided by?
1. union temp
2. {
3. char a;
4. int b;
5. float c;
6. };
a) char
b) int
c) float
d) both int and float
View Answer
Answer: d
Explanation: None.
advertisement
advertisement
#include <stdio.h>
printf("%.0f", 2.89);
a) 2.890000
b) 2.89
c) 2
d) 3
View Answer
Answer: d
Explanation: None.
2. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. float a = 2.455555555555;
5. printf("%f", a);
6. }
a) 2.455555
b) 2.455556
c) 2.456
d) 2.46
View Answer
Answer: a
Explanation: None.
advertisement
10.0000000001
a) int
b) float
c) double
Terminator21 C programming vrushabh
2*9+3/2.0
a) int
b) long
c) float
d) double
View Answer
Answer: d
Explanation: None.
7. %lf is used to display?
a) float
b) long float
c) double
d) all of the mentioned
View Answer
Answer: c
Explanation: None.
#include <stdio.h>
printf("%d", sizeof('a'));
a) 1
b) 2
c) 4
d) None of the mentioned
View Answer
Answer: c
Explanation: None.
3. Size of an array can be evaluated by __________
advertisement
a) sizeof(a);
b) sizeof(*a);
c) sizeof(a[10]);
d) 10 * sizeof(a);
View Answer
Answer: a
Explanation: None.
4. What will be the output of the following C code?
1. #include <stdio.h>
2. union temp
3. {
4. char a;
5. char b;
6. int c;
7. }t;
8. int main()
9. {
10. printf("%d", sizeof(t));
11. return 0;
Terminator21 C programming vrushabh
12. }
a) 1
b) 2
c) 4
d) 6
View Answer
Answer: c
Explanation: None.
advertisement
//Let P be a structure
//Let Q be a union
advertisement
//Let P be a structure
//Let Q be a union
advertisement
1. #include <stdio.h>
2. struct temp
3. {
4. int a[10];
Terminator21 C programming vrushabh
5. char p;
6. };
a) 5
b) 11
c) 41
d) 44
View Answer
Answer: d
Explanation: None.
4. What will be the output of the following C code?
1. #include <stdio.h>
2. main()
3. {
4. int a = 1;
5. printf("size of a is %d, ", sizeof(++a));
6. printf("value of a is %d", a);
7. };
a) size of a is 4, value of a is 1
b) size of a is 4, value of a is 2
c) size of a is 2, value of a is 2
d) size of a is 2, value of a is 2
View Answer
Answer: a
Explanation: None.
advertisement
1. #include <stdio.h>
2. printf("%d", sizeof(strlen("HELLOWORLD")));
a) Output, 4
b) Output, 10
c) Output, 16
d) Error, sizeof cannot evaluate size of a function
View Answer
Answer: a
Explanation: None.
7. Which of the following cannot be used inside sizeof?
a) pointers
b) functions
c) macro definition
Terminator21 C programming vrushabh
1. #include <stdio.h>
2. (sizeof double = 8, float = 4, void = 1)
3. #define PI 3.14
4. int main()
5. {
6. printf("%d", sizeof(PI));
7. }
a) Output is 8
b) Output is 4
c) Output is 1
d) Error, we can’t use sizeof on macro-definitions
View Answer
Answer: a
Explanation: None.