Вы находитесь на странице: 1из 37

1. C99 standard guarantees uniqueness of 5.

Why do variable names beginning with


____ characters for internal names. the underscore is not encouraged?
a) 31 a) It is not standardized
b) 63 b) To avoid conflicts since assemblers and
c) 12 loaders use such names
d) 14 c) To avoid conflicts since library routines
View Answer use such names
d) To avoid conflicts with environment
Answer: b variables of an operating system
Explanation: ISO C99 compiler may View Answer
consider only first 63 characters for internal
names. 6. All keywords in C are in ____________
a) LowerCase letters
2. C99 standard guarantees uniqueness of b) UpperCase letters
_____ characters for external names. c) CamelCase letters
a) 31 d) None of the mentioned
b) 6 View Answer
c) 12
d) 14 7. Variable name resolution (number of
View Answer significant characters for the uniqueness of
variable) depends on ___________
Answer: a a) Compiler and linker implementations
Explanation: ISO C99 compiler may b) Assemblers and loaders implementations
consider only first 31 characters for external c) C language
names. d) None of the mentioned
View Answer
3. Which of the following is not a valid
variable name declaration? advertisement
a) int __a3;
b) int __3a; 8. Which of the following is not a valid C
c) int __A3; variable name?
d) None of the mentioned a) int number;
View Answer b) float rate;
c) int variable_count;
Answer: d d) int $main;
Explanation: None. View Answer

4. Which of the following is not a valid 9. Which of the following is true for variable
variable name declaration? names in C?
a) int _a3; a) They can contain alphanumeric characters
b) int a_3; as well as special characters
c) int 3_a; b) It is not an error to declare a variable to
d) int _3a be one of the keywords(like goto, static)
View Answer c) Variable names cannot start with a digit
d) Variable can be of any length
1. Which is valid C expression? d) #define PI 3.14
a) int my_num = 100,000; View Answer
b) int my_num = 100000;
c) int my num = 1000; 5. What will happen if the following C code
d) int $my_num = 10000; is executed?
View Answer
1. #include <stdio.h>
2. What will be the output of the following 2. int main()
3. {
C code? 4. int main = 3;
5. printf("%d", main);
1. #include <stdio.h> 6. return 0;
2. int main() 7. }
3. {
4. printf("Hello World!
%d \n", x); a) It will cause a compile-time error
5. return 0; b) It will cause a run-time error
6. } c) It will run without any error and prints 3
d) It will experience infinite looping
a) Hello World! x; View Answer
b) Hello World! followed by a junk value
c) Compile time error 6. What is the problem in following variable
d) Hello World! declaration?
View Answer
float 3Bedroom-Hall-Kitchen?;
3. What will be the output of the following advertisement
C code?
a) The variable name begins with an integer
1. #include <stdio.h> b) The special character ‘-‘
2. int main() c) The special character ‘?’
3. { d) All of the mentioned
4. int y = 10000;
View Answer
5. int y = 34;
6. printf("Hello World!
%d\n", y); 7. What will be the output of the following
7. return 0; C code?
8. }
1. #include <stdio.h>
a) Compile time error 2. int main()
b) Hello World! 34 3. {
4. int ThisIsVariableName
c) Hello World! 1000 = 12;
d) Hello World! followed by a junk value 5. int ThisIsVariablename
View Answer = 14;
6. printf("%d",
4. Which of the following is not a valid ThisIsVariablename);
7. return 0;
variable name declaration? 8. }
a) float PI = 3.14;
b) double PI = 3.14; a) The program will print 12
c) int PI = 3.14; b) The program will print 14
c) The program will have a runtime error
d) The program will cause a compile-time 3. Which data type is most suitable for
error due to redeclaration storing a number 65000 in a 32-bit system?
View Answer a) signed short
b) unsigned short
8. Which of the following cannot be a c) long
variable name in C? d) int
a) volatile View Answer
b) true
c) friend 4. Which of the following is a User-defined
d) export data type?
a) typedef int Boolean;
1. What will be the output of the following b) typedef enum {Mon, Tue, Wed, Thu, Fri}
C code? Workdays;
c) struct {char name[10], int age};
1. #include <stdio.h> d) all of the mentioned
2. int main() View Answer
3. {
4. int a[5] = {1, 2, 3,
4, 5}; 5. What is the size of an int data type?
5. int i; a) 4 Bytes
6. for (i = 0; i < 5; b) 8 Bytes
i++)
7. if ((char)a[i] ==
c) Depends on the system/compiler
'5') d) Cannot be determined
8. printf("%d\n", View Answer
a[i]);
9. else 6. What is the output of the following C
10.
printf("FAIL\n"); code?
11. }
1. #include <stdio.h>
2. int main()
a) The compiler will flag an error 3. {
b) The program will compile and print the 4. signed char chr;
output 5 5. chr = 128;
c) The program will compile and print the 6. printf("%d\n", chr);
7. return 0;
ASCII value of 5
8. }
d) The program will compile and print FAIL
for 5 times
a) 128
View Answer
b) -128
c) Depends on the compiler
2. The format identifier ‘%i’ is also used for d) None of the mentioned
_____ data type. View Answer
a) char
b) int
7. What will be the output of the following
c) float
C code?
d) double
View Answer advertisement

1. #include <stdio.h>
2. int main()
3. { d) none of the mentioned
4. char c; View Answer
5. int i = 0;
6. FILE *file;
7. file = 2. What will be the output of the following
fopen("test.txt", "w+"); C code?
8. fprintf(file, "%c",
'a'); 1. #include <stdio.h>
9. fprintf(file, "%c", - 2. int main()
1); 3. {
10. fprintf(file, "%c", 4. float f1 = 0.1;
'b'); 5. if (f1 == 0.1f)
11. fclose(file); 6. printf("equal\n");
12. file = 7. else
fopen("test.txt", "r"); 8. printf("not
13. while ((c = equal\n");
fgetc(file)) != -1) 9. }
14. printf("%c", c);
15. return 0;
16. } a) equal
b) not equal
a) a c) output depends on compiler
b) Infinite loop d) none of the mentioned
c) Depends on what fgetc returns View Answer
d) Depends on the compiler
View Answer 3. What will be the output of the following
C code on a 32-bit machine?
8. What is short int in C programming?
a) The basic data type of C 1. #include <stdio.h>
2. int main()
b) Qualifier 3. {
c) Short is the qualifier and int is the basic 4. int x = 10000;
data type 5. double y = 56;
d) All of the mentioned 6. int *p = &x;
7. double *q = &y;
8. printf("p and q are %d
1. What will be the output of the following and %d", sizeof(p),
C code? sizeof(q));
9. return 0;
1. #include <stdio.h> 10. }
2. int main()
3. { a) p and q are 4 and 4
4. float f1 = 0.1;
b) p and q are 4 and 8
5. if (f1 == 0.1)
6. printf("equal\n"); c) compiler error
7. else d) p and q are 2 and 8
8. printf("not View Answer
equal\n");
9. }
4. Which is correct with respect to the size
of the data types?
a) equal
a) char > int > float
b) not equal
b) int > char > float
c) output depends on the compiler
c) char < int < double
d) double > char > int c) float
View Answer d) double

5. What will be the output of the following 1. What will be the output of the following
C code on a 64 bit machine? C code?

1. #include <stdio.h> 1. #include <stdio.h>


2. union Sti 2. int main()
3. { 3. {
4. int nu; 4. enum {ORANGE = 5,
5. char m; MANGO, BANANA = 4, PEACH};
6. }; 5. printf("PEACH = %d\n",
7. int main() PEACH);
8. { 6. }
9. union Sti s;
10. printf("%d",
a) PEACH = 3
sizeof(s));
11. return 0; b) PEACH = 4
12. } c) PEACH = 5
d) PEACH = 6
a) 8 View Answer
b) 5
c) 9 2. What will be the output of the following
d) 4 C code?
View Answer
1. #include <stdio.h>
advertisement 2. int main()
3. {
4. printf("C programming
6. What will be the output of the following %s", "Class by\n%s
C code? Sanfoundry", "WOW");
5. }
1. #include <stdio.h>
2. int main() a)
3. {
4. float x = 'a';
C programming Class by
5. printf("%f", x); WOW Sanfoundry
6. return 0;
7. }
b) C programming Class by\n%s
a) a Sanfoundry
b) run time error c)
c) a.0000000
C programming Class by
d) 97.000000 %s Sanfoundry
View Answer
d) Compilation error
7. Which of the data types has the size that is View Answer
variable?
a) int 3. In the following code snippet, character
b) struct pointer str holds a reference to the string
___________
char *str = "Sanfoundry.com\0" 3. enum animals {TIGER = 8,
"training classes"; LION, RABBIT, ZEBRA};
4. int main()
5. {
a) Sanfoundry.com
6. enum birds m = TIGER;
b) Sanfoundry.com\0training classes 7. int k;
c) Sanfoundry.comtraining classes 8. k = m;
d) Invalid declaration 9. printf("%d\n", k);
View Answer 10. return 0;
11. }
4. What will be the output of the following
a) 0
C code?
b) Compile time error
1. #include <stdio.h> c) 1
2. #define a 10 d) 8
3. int main() View Answer
4. {
5. const int a = 5;
6. printf("a = %d\n", a);
7. What will be the output of the following
7. } C code?

1. #include <stdio.h>
a) a = 5
2. #define MAX 2
b) a = 10 3. enum bird {SPARROW = MAX +
c) Compilation error 1, PARROT = SPARROW + MAX};
d) Runtime error 4. int main()
View Answer 5. {
6. enum bird b = PARROT;
7. printf("%d\n", b);
5. What will be the output of the following 8. return 0;
C code? 9. }

1. #include <stdio.h> a) Compilation error


2. int main() b) 5
3. {
4. int var = 010; c) Undefined value
5. printf("%d", var); d) 2
6. } View Answer

a) 2 8. What will be the output of the following


b) 8 C code?
c) 9
d) 10 1. #include <stdio.h>
View Answer 2. #include <string.h>
3. int main()
4. {
advertisement 5. char *str = "x";
6. char c = 'x';
6. What will be the output of the following 7. char ary[1];
C function? 8. ary[0] = c;
9. printf("%d %d",
strlen(str), strlen(ary));
1. #include <stdio.h>
10. return 0;
2. enum birds {SPARROW,
11. }
PEACOCK, PARROT};
a) 1 1 c) classundry
b) 2 1 d) sanfoundry
c) 2 2 View Answer
d) 1 (undefined value)
4. What will be the output of the following
1. enum types are processed by _________ C code?
a) Compiler
b) Preprocessor 1. #include <stdio.h>
c) Linker 2. int main()
3. {
d) Assembler 4. const int p;
View Answer 5. p = 4;
6. printf("p is %d", p);
2. What will be the output of the following 7. return 0;
8. }
C code?

1. #include <stdio.h> a) p is 4
2. int main() b) Compile time error
3. { c) Run time error
4. d) p is followed by a garbage value
printf("sanfoundry\rclass\n");
5. return 0;
View Answer
6. }
advertisement
a) sanfoundryclass
b) 5. What will be the output of the following
C code?
sanfoundry
class 1. #include <stdio.h>
2. void main()
3. {
c) classundry 4. int k = 4;
d) sanfoundry 5. int *const p = &k;
View Answer 6. int r = 3;
7. p = &r;
8. printf("%d", p);
3. What will be the output of the following 9. }
C code?
a) Address of k
1. #include <stdio.h>
2. int main() b) Address of r
3. { c) Compile time error
4. d) Address of k + address of r
printf("sanfoundry\r\nclass\n" View Answer
);
5. return 0;
6. } 6. Which of the following statement is false?
a) Constant variables need not be defined as
a) sanfoundryclass they are declared and can be defined later
b) b) Global constant variables are initialized to
zero
sanfoundry c) const keyword is used to define constant
class values
d) You cannot reassign a value to a constant 4. {
variable 5. const int i = 10;
6. printf("%d ", i);
View Answer 7. foo(&i);
8. printf("%d", i);
7. What will be the output of the following 9.
C code? 10. }
11. void foo(const int *i)
12. {
1. #include <stdio.h>
13. *i = 20;
2. void main() 14. }
3. {
4. int const k = 5;
5. k++; a) Compile time error
6. printf("k is %d", k); b) 10 20
7. } c) Undefined value
d) 10
a) k is 6 View Answer
b) Error due to const succeeding int
c) Error, because a constant variable can be 2. What will be the output of the following
changed only twice C code?
d) Error, because a constant variable cannot
be changed 1. #include <stdio.h>
View Answer 2. int main()
3. {
4. const int i = 10;
8. What will be the output of the following 5. int *ptr = &i;
C code? 6. *ptr = 20;
7. printf("%d\n", i);
1. #include <stdio.h> 8. return 0;
2. int const print() 9. }
3. {
4.
a) Compile time error
printf("Sanfoundry.com");
5. return 0; b) Compile time warning and printf displays
6. } 20
7. void main() c) Undefined behaviour
8. { d) 10
9. print();
10. }
View Answer

a) Error because function name cannot be 3. What will be the output of the following
preceded by const C code?
b) Sanfoundry.com
1. #include <stdio.h>
c) Sanfoundry.com is printed infinite times 2. int main()
d) Blank screen, no output 3. {
4. j = 10;
1. What will be the output of the following 5. printf("%d\n", j++);
6. return 0;
C code? 7. }

1. #include <stdio.h>
2. void foo(const int *); a) 10
3. int main() b) 11
c) Compile time error d) Both String str; & float str = 3e2;
d) 0 View Answer
View Answer
7. Which of the following format identifier
4. Will the following C code compile can never be used for the variable var?
without any error?
1. #include <stdio.h>
1. #include <stdio.h> 2. int main()
2. int main() 3. {
3. { 4. char *var = "Advanced
4. for (int k = 0; k < Training in C by
10; k++); Sanfoundry.com";
5. return 0; 5. }
6. }
a) %f
a) Yes b) %d
b) No c) %c
c) Depends on the C standard implemented d) %s
by compilers
d) None of the mentioned 1. Which of the following declaration is
View Answer illegal?
a) char *str = “Best C programming classes
advertisement by Sanfoundry”;
b) char str[] = “Best C programming classes
5. Will the following C code compile by Sanfoundry”;
without any error? c) char str[20] = “Best C programming
classes by Sanfoundry”;
1. #include <stdio.h> d) char[] str = “Best C programming classes
2. int main()
3. { by Sanfoundry”;
4. int k; View Answer
5. {
6. int k; 2. Which keyword is used to prevent any
7. for (k = 0; k <
10; k++);
changes in the variable within a C program?
8. } a) immutable
9. } b) mutable
c) const
a) Yes d) volatile
b) No View Answer
c) Depends on the compiler
d) Depends on the C standard implemented 3. Which of the following is not a pointer
by compilers declaration?
View Answer a) char a[10];
b) char a[] = {‘1’, ‘2’, ‘3’, ‘4’};
6. Which of the following declaration is not c) char *str;
supported by C? d) char a;
a) String str; View Answer
b) char *str;
c) float str = 3e2;
4. What will be the output of the following 2. int main()
C code? 3. {
4. int i = -3;
5. int k = i % 2;
1. #include <stdio.h> 6. printf("%d\n", k);
2. void main() 7. }
3. {
4. int k = 4;
5. float k = 4; a) Compile time error
6. printf("%d", k) b) -1
7. } c) 1
d) Implementation defined
a) Compile time error View Answer
b) 4
c) 4.0000000 2. What will be the output of the following
d) 4.4 C code?
View Answer
1. #include <stdio.h>
5. Which of the following statement is false? 2. int main()
a) A variable defined once can be defined 3. {
4. int i = 3;
again with different scope 5. int l = i / -2;
b) A single variable cannot be defined with 6. int k = i % -2;
two different types in the same scope 7. printf("%d %d\n", l,
c) A variable must be declared and defined k);
8. return 0;
at the same time 9. }
d) A variable refers to a location in memory
View Answer a) Compile time error
b) -1 1
advertisement
c) 1 -1
d) Implementation defined
6. A variable declared in a function can be
View Answer
used in main().
a) True
3. What will be the output of the following
b) False
C code?
c) True if it is declared static
d) None of the mentioned 1. #include <stdio.h>
View Answer 2. int main()
3. {
7. The name of the variable used in one 4. int i = 5;
function cannot be used in another function. 5. i = i / 3;
6. printf("%d\n", i);
a) True 7. return 0;
b) False 8. }
c) May be
d) None of the mentioned a) Implementation defined
b) 1
1. What will be the output of the following c) 3
C code? d) Compile time error
View Answer
1. #include <stdio.h>
4. What will be the output of the following d) Compile time error
C code? View Answer

1. #include <stdio.h> 7. What will be the output of the following


2. int main() C code?
3. {
4. int i = -5;
5. i = i / 3; 1. #include <stdio.h>
6. printf("%d\n", i); 2. void main()
7. return 0; 3. {
8. } 4. int y = 3;
5. int x = 5 % 2 * 3 / 2;
6. printf("Value of x is
a) Implementation defined %d", x);
b) -1 7. }
c) -3
d) Compile time error a) Value of x is 1
View Answer b) Value of x is 2
c) Value of x is 3
advertisement d) Compile time error

5. What will be the final value of x in the 1. What will be the output of the following
following C code? C code?
1. #include <stdio.h> 1. #include <stdio.h>
2. void main() 2. void main()
3. { 3. {
4. int x = 5 * 9 / 3 + 9; 4. int a = 3;
5. } 5. int b = ++a + a++ + --
a;
a) 3.75 6. printf("Value of b is
%d", b);
b) Depends on compiler
7. }
c) 24
d) 3
a) Value of x is 12
View Answer
b) Value of x is 13
c) Value of x is 10
6. What will be the output of the following d) Undefined behaviour
C code? View Answer
1. #include <stdio.h>
2. void main() 2. What is the precedence of arithmetic
3. { operators (from highest to lowest)?
4. int x = 5.3 % 2; a) %, *, /, +, –
5. printf("Value of x is b) %, +, /, *, –
%d", x);
6. } c) +, -, %, *, /
d) %, +, -, *, /
a) Value of x is 2.3 View Answer
b) Value of x is 1
c) Value of x is 0.3 3. Which of the following is not an
arithmetic operation?
a) a *= 10; 1. #include <stdio.h>
b) a /= 10; 2. int main()
3. {
c) a != 10; 4. int a = 10, b = 5, c =
d) a %= 10; 5;
View Answer 5. int d;
6. d = a == (b + c);
7. printf("%d", d);
4. Which of the following data type will 8. }
throw an error on modulus operation(%)?
a) char a) Syntax error
b) short b) 1
c) int c) 10
d) float d) 5
View Answer
1. What will be the output of the following
5. Which among the following are the C code?
fundamental arithmetic operators, i.e,
performing the desired operation can be 1. #include <stdio.h>
done using that operator only? 2. void main()
a) +, – 3. {
b) +, -, % 4. int x = 1, y = 0, z =
5;
c) +, -, *, / 5. int a = x && y || z++;
d) +, -, *, /, % 6. printf("%d", z);
View Answer 7. }

6. What will be the output of the following a) 6


C code? b) 5
c) 0
1. #include <stdio.h> d) Varies
2. int main() View Answer
3. {
4. int a = 10;
5. double b = 5.6; 2. What will be the output of the following
6. int c; C code?
7. c = a + b;
8. printf("%d", c); 1. #include <stdio.h>
9. } 2. void main()
3. {
a) 15 4. int x = 1, y = 0, z =
b) 16 5;
5. int a = x && y && z++;
c) 15.6 6. printf("%d", z);
d) 10 7. }
View Answer
a) 6
advertisement b) 5
c) 0
7. What will be the output of the following d) Varies
C code? View Answer
3. What will be the output of the following c) 2
C code? d) Run time error
View Answer
1. #include <stdio.h>
2. int main() 6. What will be the final value of j in the
3. {
4. int x = 1, y = 0, z = following C code?
3;
5. x > y ? printf("%d", 1. #include <stdio.h>
z) : return z; 2. int main()
6. } 3. {
4. int i = 0, j = 0;
5. if (i && (j = i + 10))
a) 3 6. //do something
b) 1 7. ;
c) Compile time error 8. }
d) Run time error
View Answer a) 0
b) 10
4. What will be the output of the following c) Depends on the compiler
C code? d) Depends on language standard
View Answer
1. #include <stdio.h>
2. void main() 7. What will be the final value of j in the
3. {
4. int x = 1, z = 3; following C code?
5. int y = x << 3;
6. printf(" %d\n", y); 1. #include <stdio.h>
7. } 2. int main()
3. {
4. int i = 10, j = 0;
a) -2147483648 5. if (i || (j = i + 10))
b) -1 6. //do something
c) Run time error 7. ;
d) 8 8. }
View Answer
a) 0
advertisement b) 20
c) Compile time error
5. What will be the output of the following d) Depends on language standard
C code? View Answer

1. #include <stdio.h> 8. What will be the output of the following


2. void main() C code?
3. {
4. int x = 0, y = 2, z =
3; 1. #include <stdio.h>
5. int a = x & y | z; 2. int main()
6. printf("%d", a); 3. {
7. } 4. int i = 1;
5. if (i++ && (i == 1))
6. printf("Yes\n");
a) 3 7. else
b) 0 8. printf("No\n");
9. } d) 10
View Answer
a) Yes
b) No 5. What will be the output of the following
c) Depends on the compiler C code?
d) Depends on the standard
1. #include <stdio.h>
1. Are logical operator sequence points? 2. int main()
a) True 3. {
4. int a = 10, b = 5, c =
b) False 3;
c) Depends on the compiler 5. b != !a;
d) Depends on the standard 6. c = !!a;
View Answer 7. printf("%d\t%d", b,
c);
8. }
2. Do logical operators in the C language are
evaluated with the short circuit? a) 5 1
a) True b) 0 3
b) False c) 5 3
c) Depends on the compiler d) 1 1
d) Depends on the standard View Answer
View Answer
6. Which among the following is NOT a
3. What is the result of a logical or relational logical or relational operator?
expression in C? a) !=
a) True or False b) ==
b) 0 or 1 c) ||
c) 0 if an expression is false and any positive d) =
number if an expression is true View Answer
d) None of the mentioned
View Answer advertisement

4. What will be the final value of d in the 7. What will be the output of the following
following C code? C code?
1. #include <stdio.h> 1. #include <stdio.h>
2. int main() 2. int main()
3. { 3. {
4. int a = 10, b = 5, c = 4. int a = 10;
5; 5. if (a == a--)
5. int d; 6. printf("TRUE
6. d = b + c == a; 1\t");
7. printf("%d", d); 7. a = 10;
8. } 8. if (a == --a)
9. printf("TRUE
a) Syntax error 2\t");
b) 1 10. }
c) 5
a) TRUE 1 3. What will be the output of the following
b) TRUE 2 C code? (Initial values: x= 7, y = 8)
c) TRUE 1 TRUE 2
d) Compiler Dependent 1. #include <stdio.h>
View Answer 2. void main()
3. {
4. float x;
8. Relational operators cannot be used on 5. int y;
____________ 6. printf("enter two
a) structure numbers \n", x);
7. scanf("%f %f", &x,
b) long &y);
c) strings 8. printf("%f, %d", x,
d) float y);
9. }
1. What will be the output of the following
C code? a) 7.000000, 7
b) Run time error
1. #include <stdio.h> c) 7.000000, junk
2. void main() d) Varies
3. { View Answer
4. float x = 0.1;
5. if (x == 0.1)
6. 4. What will be the output of the following
printf("Sanfoundry"); C code?
7. else
8. printf("Advanced C 1. #include <stdio.h>
Classes"); 2. void main()
9. } 3. {
4. double x =
a) Advanced C Classes 123828749.66;
b) Sanfoundry 5. int y = x;
6. printf("%d\n", y);
c) Run time error 7. printf("%lf\n", y);
d) Compile time error 8. }
View Answer
a) 0, 0.0
2. What will be the output of the following b) 123828749, 123828749.66
C code? c) 12382874, 12382874.0
d) 123828749, 0.000000
1. #include <stdio.h>
View Answer
2. void main()
3. {
4. float x = 0.1; 5. What will be the output of the following
5. printf("%d, ", x); C code?
6. printf("%f", x);
7. } advertisement

a) 0.100000, junk value 1. #include <stdio.h>


b) Junk value, 0.100000 2. void main()
3. {
c) 0, 0.100000 4. int x = 97;
d) 0, 0.999999 5. char y = x;
View Answer 6. printf("%c\n", y);
7. } a) Yes
b) No
a) a c) Depends on the compiler
b) b d) Depends on the standard
c) 97
d) Run time error 1. function tolower(c) defined in library
View Answer <ctype.h> works for ___________
a) Ascii character set
6. When double is converted to float, then b) Unicode character set
the value is? c) Ascii and utf-8 but not EBCDIC character
a) Truncated set
b) Rounded d) Any character set
c) Depends on the compiler View Answer
d) Depends on the standard
View Answer 2. What will be the output of the following
C code considering the size of short int is 2,
7. What will be the output of the following char is 1 and int is 4 bytes?
C code?
1. #include <stdio.h>
1. #include <stdio.h> 2. int main()
2. int main() 3. {
3. { 4. short int i = 20;
4. unsigned int i = 23; 5. char c = 97;
5. signed char c = -23; 6. printf("%d, %d, %d\n",
6. if (i > c) sizeof(i), sizeof(c), sizeof(c
7. printf("Yes\n"); + i));
8. else if (i < c) 7. return 0;
9. printf("No\n"); 8. }
10. }
a) 2, 1, 2
a) Yes b) 2, 1, 1
b) No c) 2, 1, 4
c) Depends on the compiler d) 2, 2, 8
d) Depends on the operating system View Answer
View Answer
3. Which type of conversion is NOT
8. What will be the output of the following accepted?
C code? a) From char to int
b) From float to char pointer
1. #include <stdio.h> c) From negative int to char
2. int main()
3. { d) From double to char
4. int i = 23; View Answer
5. char c = -23;
6. if (i < c) 4. What will be the data type of the result of
7. printf("Yes\n");
8. else
the following operation?
9. printf("No\n");
10. } (float)a * (int)b / (long)c *
(double)d
a) int 3. {
b) long 4. int d, a = 1, b = 2;
5. d = a++ +++b;
c) float 6. printf("%d %d %d", d,
d) double a, b);
View Answer 7. }

5. Which of the following type-casting have a) No difference as space doesn’t make any
chances for wrap around? difference, values of a, b, d are same in both
a) From int to float the case
b) From int to char b) Space does make a difference, values of
c) From char to short a, b, d are different
d) From char to int c) Program 1 has syntax error, program 2 is
View Answer not
d) Program 2 has syntax error, program 1 is
6. Which of the following typecasting is not
accepted by C? View Answer
a) Widening conversions
b) Narrowing conversions 2. What will be the output of the following
c) Widening & Narrowing conversions C code?
d) None of the mentioned
View Answer 1. #include <stdio.h>
2. int main()
3. {
advertisement 4. int a = 1, b = 1, c;
5. c = a++ + b;
7. When do you need to use type- 6. printf("%d, %d", a,
conversions? b);
a) The value to be stored is beyond the max 7. }
limit
b) The value to be stored is in a form not a) a = 1, b = 1
supported by that data type b) a = 2, b = 1
c) To reduce the memory in use, relevant to c) a = 1, b = 2
the value d) a = 2, b = 2
d) All of the mentioned View Answer

1. What is the difference between the 3. What will be the output of the following
following 2 codes? C code?

1. #include <stdio.h> 1. #include <stdio.h>


//Program 1 2. int main()
2. int main() 3. {
3. { 4. int a = 1, b = 1, d =
4. int d, a = 1, b = 2; 1;
5. d = a++ + ++b; 5. printf("%d, %d, %d",
6. printf("%d %d %d", d, ++a + ++a+a++, a++ + ++b, ++d
a, b); + d++ + a++);
7. } 6. }
1. #include <stdio.h>
//Program 2
2. int main()
a) 15, 4, 5 d) Compile time error
b) 9, 6, 9 View Answer
c) 9, 3, 5
d) Undefined (Compiler Dependent) 7. What will be the output of the following
View Answer C code?

4. For which of the following, “PI++;” code 1. #include <stdio.h>


will fail? 2. int main()
3. {
a) #define PI 3.14 4. int i = 2;
b) char *PI = “A”; 5. int j = ++i + i;
c) float PI = 3.14; 6. printf("%d\n", j);
d) none of the Mentioned 7. }
View Answer
a) 6
5. What will be the output of the following b) 5
C code? c) 4
d) Compile time error
advertisement View Answer
1. #include <stdio.h>
8. What will be the output of the following
2. int main()
3. { C code?
4. int a = 10, b = 10;
5. if (a = 5) 1. #include <stdio.h>
6. b--; 2. int main()
7. printf("%d, %d", a, b- 3. {
-); 4. int i = 2;
8. } 5. int i = i++ + i;
6. printf("%d\n", i);
7. }
a) a = 10, b = 9
b) a = 10, b = 8
c) a = 5, b = 9 a) = operator is not a sequence point
d) a = 5, b = 8 b) ++ operator may return value with or
View Answer without side effects
c) it can be evaluated as (i++)+i or i+(++i)
d) = operator is a sequence point
6. What will be the output of the following
C code?
1. What will be the output of the following
1. #include <stdio.h> C code?
2. int main()
3. { 1. #include <stdio.h>
4. int i = 0; 2. int main()
5. int j = i++ + i; 3. {
6. printf("%d\n", j); 4. int i = 0;
7. } 5. int x = i++, y = ++i;
6. printf("%d % d\n", x,
y);
a) 0 7. return 0;
b) 1 8. }
c) 2
a) 0, 2 7. printf("%d%d%d", x,
b) 0, 1 y, z);
8. }
c) 1, 2
d) Undefined
a) 3 2 3
View Answer
b) 2 3 3
c) 3 2 2
2. What will be the output of the following
d) 2 3 4
C code?
View Answer
1. #include <stdio.h>
2. int main() advertisement
3. {
4. int i = 10; 5. What will be the output of the following
5. int *p = &i; C code?
6. printf("%d\n", *p++);
7. }
1. #include <stdio.h>
2. void main()
a) 10 3. {
b) 11 4. int x = 4;
c) Garbage value 5. int *p = &x;
6. int *k = p++;
d) Address of i 7. int r = p - k;
View Answer 8. printf("%d", r);
9. }
3. What will be the output of the following
C code? a) 4
b) 8
1. #include <stdio.h> c) 1
2. void main() d) Run time error
3. {
4. int x = 97; View Answer
5. int y = sizeof(x++);
6. printf("X is %d", x); 6. What will be the output of the following
7. } C code?

a) X is 97 1. #include <stdio.h>
b) X is 98 2. void main()
c) X is 99 3. {
4. int a = 5, b = -7, c =
d) Run time error 0, d;
View Answer 5. d = ++a && ++b || ++c;
6. printf("\n%d%d%d%d",
4. What will be the output of the following a, b, c, d);
7. }
C code?

1. #include <stdio.h> a) 6 -6 0 0
2. void main() b) 6 -5 0 1
3. { c) -6 -6 0 1
4. int x = 4, y, z; d) 6 -6 0 1
5. y = --x;
6. z = x--;
View Answer
7. What will be the output of the following 3. What will be the output of the following
C code? C code?

1. #include <stdio.h> 1. #include <stdio.h>


2. void main() 2. int main()
3. { 3. {
4. int a = -5; 4. if (7 & 8)
5. int k = (a++, ++a); 5. printf("Honesty");
6. printf("%d\n", k); 6. if ((~7 & 0x000f)
7. } == 8)
7. printf("is the
a) -4 best policy\n");
8. }
b) -5
c) 4
a) Honesty is the best policy
d) -3
b) Honesty
c) is the best policy
1. What will be the output of the following
d) No output
C code?
View Answer
1. #include <stdio.h>
2. int main() 4. What will be the output of the following
3. { C code?
4. int c = 2 ^ 3;
5. printf("%d\n", c); 1. #include <stdio.h>
6. } 2. int main()
3. {
a) 1 4. int a = 2;
b) 8 5. if (a >> 1)
6. printf("%d\n", a);
c) 9 7. }
d) 0
View Answer a) 0
b) 1
2. What will be the output of the following c) 2
C code? d) No Output
View Answer
1. #include <stdio.h>
2. int main()
3. { advertisement
4. unsigned int a = 10;
5. a = ~a; 5. Comment on the output of the following
6. printf("%d\n", a); C code.
7. }
1. #include <stdio.h>
a) -9 2. int main()
b) -10 3. {
c) -11 4. int i, n, a = 4;
5. scanf("%d", &n);
d) 10 6. for (i = 0; i < n;
View Answer i++)
7. a = a * 2;
8. }
a) Logical Shift left 6. int *k = p++;
b) No output 7. int r = p - k;
8. printf("%d", r);
c) Arithmetic Shift right 9. }
d) Bitwise exclusive OR
View Answer a) 4
b) 8
6. What will be the output of the following c) 1
C code? d) Run time error
1. #include <stdio.h>
2. void main()
1. What will be the output of the following
3. { C code?
4. int x = 97;
5. int y = sizeof(x++); 1. #include <stdio.h>
6. printf("x is %d", x); 2. void main()
7. } 3. {
4. int a = 5, b = -7, c =
a) x is 97 0, d;
5. d = ++a && ++b || ++c;
b) x is 98 6. printf("\n%d%d%d%d",
c) x is 99 a, b, c, d);
d) Run time error 7. }
View Answer
a) 6 -6 0 0
7. What will be the output of the following b) 6 -5 0 1
C code? c) -6 -6 0 1
d) 6 -6 0 1
1. #include <stdio.h> View Answer
2. void main()
3. {
4. int x = 4, y, z;
2. What will be the output of the following
5. y = --x; C code?
6. z = x--;
7. printf("%d%d%d", x, y, 1. #include <stdio.h>
z); 2. void main()
8. } 3. {
4. int a = -5;
a) 3 2 3 5. int k = (a++, ++a);
6. printf("%d\n", k);
b) 2 2 3 7. }
c) 3 2 2
d) 2 3 3 a) -3
View Answer b) -5
c) 4
8. What will be the output of the following d) Undefined
C code? View Answer
1. #include <stdio.h>
2. void main()
3. What will be the output of the following
3. { C code?
4. int x = 4;
5. int *p = &x; 1. #include <stdio.h>
2. int main() 6. What will be the output of the following
3. { C code?
4. int x = 2;
5. x = x << 1;
6. printf("%d\n", x); 1. #include <stdio.h>
7. } 2. int main()
3. {
4. int x = -2;
a) 4 5. if (!0 == 1)
b) 1 6. printf("yes\n");
c) Depends on the compiler 7. else
d) Depends on the endianness of the 8. printf("no\n");
9. }
machine
View Answer
a) yes
b) no
4. What will be the output of the following
c) run time error
C code?
d) undefined
1. #include <stdio.h>
View Answer
2. int main()
3. { 7. What will be the output of the following
4. int x = -2; C code?
5. x = x >> 1;
6. printf("%d\n", x);
1. #include <stdio.h>
7. }
2. int main()
3. {
a) 1 4. int y = 0;
b) -1 5. if (1 |(y = 1))
c) 2 31 – 1 considering int to be 4 bytes 6. printf("y is
%d\n", y);
d) Either -1 or 1 7. else
View Answer 8. printf("%d\n", y);
9.
advertisement 10. }

5. What will be the output of the following a) y is 1


C code? b) 1
c) run time error
1. #include <stdio.h> d) undefined
2. int main() View Answer
3. {
4. if (~0 == 1)
5. printf("yes\n"); 8. What will be the output of the following
6. else C code?
7. printf("no\n");
8. } 1. #include <stdio.h>
2. int main()
a) yes 3. {
4. int y = 1;
b) no
5. if (y & (y = 2))
c) compile time error 6. printf("true
d) undefined %d\n", y);
View Answer 7. else
8. printf("false 3. What will be the output of the following
%d\n", y); C code?
9.
10. }
1. #include <stdio.h>
2. void main()
a) true 2 3. {
b) false 2 4. char a = 'a';
c) either true 2 or false 2 5. int x = (a % 10)++;
d) true 1 6. printf("%d\n", x);
7. }

1. What will be the output of the following


a) 6
C code?
b) Junk value
1. #include <stdio.h>
c) Compile time error
2. void main() d) 7
3. { View Answer
4. int x = 0;
5. if (x = 0) 4. What will be the output of the following
6. printf("Its
zero\n"); C code snippet?
7. else
8. printf("Its not 1. #include <stdio.h>
zero\n"); 2. void main()
9. } 3. {
4. 1 < 2 ? return 1:
return 2;
a) Its not zero 5. }
b) Its zero
c) Run time error a) returns 1
d) None b) returns 2
View Answer c) Varies
d) Compile time error
2. What will be the output of the following View Answer
C code?
advertisement
1. #include <stdio.h>
2. void main()
3. { 5. What will be the output of the following
4. int k = 8; C code snippet?
5. int x = 0 == 1 && k++;
6. printf("%d%d\n", x, 1. #include <stdio.h>
k); 2. void main()
7. } 3. {
4. unsigned int x = -5;
a) 0 9 5. printf("%d", x);
6. }
b) 0 8
c) 1 8
d) 1 9 a) Run time error
View Answer b) Aries
c) -5
d) 5
View Answer
6. What will be the output of the following c) 0
C code? d) Undefined behaviour

1. #include <stdio.h> 1. What is the type of the following


2. int main() assignment expression if x is of type float
3. {
4. int x = 2, y = 1; and y is of type int?
5. x *= x + y;
6. printf("%d\n", x); y = x + y;
7. return 0;
8. } a) int
b) float
a) 5 c) there is no type for an assignment
b) 6 expression
c) Undefined behaviour d) double
d) Compile time error View Answer
View Answer
2. What will be the value of the following
7. What will be the output of the following assignment expression?
C code?
(x = foo())!= 1 considering foo()
1. #include <stdio.h> returns 2
2. int main()
3. {
4. int x = 2, y = 2;
a) 2
5. x /= x / y; b) True
6. printf("%d\n", x); c) 1
7. return 0; d) 0
8. } View Answer
a) 2 3. Operation “a = a * b + a” can also be
b) 1 written as ___________
c) 0.5 a) a *= b + 1;
d) Undefined behaviour b) (c = a * b)!=(a = c + a);
View Answer c) a = (b + 1)* a;
d) All of the mentioned
8. What will be the output of the following View Answer
C code?
4. What will be the final value of c in the
1. #include <stdio.h>
2. int main() following C statement? (Initial value: c = 2)
3. {
4. int x = 1, y = 0; 1. c <<= 1;
5. x &&= y;
6. printf("%d\n", x); a) c = 1;
7. }
b) c = 2;
c) c = 3;
a) Compile time error d) c = 4;
b) 1 View Answer
5. What will be the output of the following 3. {
C code? 4. int x = 2, y = 0;
5. int z = (y++) ? y == 1
&& x : 0;
1. #include <stdio.h> 6. printf("%d\n", z);
2. int main() 7. return 0;
3. { 8. }
4. int a = 1, b = 2;
5. a += b -= a;
6. printf("%d %d", a, b); a) 0
7. } b) 1
c) Undefined behaviour
a) 1 1 d) Compile time error
b) 1 2 View Answer
c) 2 1
d) 2 2 2. What will be the output of the following
View Answer C code?

6. What will be the output of the following 1. #include <stdio.h>


C code? 2. int main()
3. {
4. int x = 1;
advertisement 5. int y = x == 1 ?
getchar(): 2;
1. #include <stdio.h> 6. printf("%d\n", y);
2. int main() 7. }
3. {
4. int a = 4, n, i,
result = 0; a) Compile time error
5. scanf("%d", n); b) Whatever character getchar function
6. for (i = 0;i < n; i++) returns
7. result += a;
8. }
c) Ascii value of character getchar function
returns
a) Addition of a and n d) 2
b) Subtraction of a and n View Answer
c) Multiplication of a and n
d) Division of a and n 3. What will be the output of the following
View Answer C code?

1. #include <stdio.h>
7. Which of the following is an invalid 2. int main()
assignment operator? 3. {
a) a %= 10; 4. int x = 1;
b) a /= 10; 5. short int i = 2;
6. float f = 3;
c) a |= 10; 7. if (sizeof((x == 2) ?
d) None of the mentioned f : i) == sizeof(float))
8. printf("float\n");
1. What will be the output of the following 9. else if (sizeof((x ==
C code? 2) ? f : i) == sizeof(short
int))
10. printf("short
1. #include <stdio.h> int\n");
2. int main() 11. }
a) float 3. {
b) short int 4. int k = 8;
5. int m = 7;
c) Undefined behaviour 6. int z = k < m ? k++ :
d) Compile time error m++;
View Answer 7. printf("%d", z);
8. }
4. What will be the output of the following
C code? a) 7
b) 8
1. #include <stdio.h> c) Run time error
2. int main() d) None of the mentioned
3. { View Answer
4. int a = 2;
5. int b = 0;
6. int y = (b == 0) ? a 7. What will be the output of the following
:(a > b) ? (b = 1): a; C code?
7. printf("%d\n", y);
8. } 1. #include <stdio.h>
2. void main()
a) Compile time error 3. {
b) 1 4. int k = 8;
5. int m = 7;
c) 2 6. int z = k < m ? k = m
d) Undefined behaviour : m++;
View Answer 7. printf("%d", z);
8. }
advertisement
a) Run time error
5. What will be the output of the following b) 7
C code? c) 8
d) Depends on compiler
1. #include <stdio.h> View Answer
2. int main()
3. {
4. int y = 1, x = 0;
8. What will be the output of the following
5. int l = (y++, x++) ? y C code?
: x;
6. printf("%d\n", l); 1. #include <stdio.h>
7. } 2. void main()
3. {
4. 1 < 2 ? return 1 :
a) 1
return 2;
b) 2 5. }
c) Compile time error
d) Undefined behaviour a) returns 1
View Answer b) returns 2
c) Varies
6. What will be the output of the following d) Compile time error
C code?
1. What will be the output of the following
1. #include <stdio.h>
2. void main()
C code?
1. #include <stdio.h> expression (a < 50)? var1 :
2. void main() var2;
3. {
4. int k = 8;
a) int
5. int m = 7;
6. k < m ? k++ : m = k; b) float
7. printf("%d", k); c) double
8. } d) Cannot be determined
View Answer
a) 7
b) 8 5. Which expression has to be present in the
c) Compile time error following?
d) Run time error
View Answer exp1 ? exp2 : exp3;

2. What will be the output of the following a) exp1


C code? b) exp2
c) exp3
1. #include <stdio.h> d) All of the mentioned
2. void main() View Answer
3. {
4. int k = 8;
5. int m = 7; 6. What will be the final value of c in the
6. k < m ? k = k + 1 : m following C code snippet? (Initial values: a
= m + 1; = 1, b = 2, c = 1)
7. printf("%d", k);
8. }
c += (-c) ? a : b;

a) Compile time error a) Syntax Error


b) 9 b) c = 1
c) 8 c) c = 2
d) Run time error d) c = 3
View Answer View Answer
3. What will be the final values of a and c in advertisement
the following C statement? (Initial values: a
= 2, c = 1) 7. The following C code can be rewritten as
_______
c = (c) ? a = 0 : 2;
c = (n) ? a : b;
a) a = 0, c = 0;
b) a = 2, c = 2; a)
c) a = 2, c = 2;
d) a = 1, c = 2; if (!n)c = b;
View Answer else c = a;

4. What will be the data type of the b)


following expression? (Initial data type: a =
int, var1 = double, var2 = float) if (n <;= 0)c = b;
else c = a;
c) d) Undefined behaviour
View Answer
if (n > 0)c = a;
else c = b; 3. In expression i = g() + f(), first function
called depends on __________
d) All of the mentioned a) Compiler
b) Associativiy of () operator
1. What will be the output of the following c) Precedence of () and + operator
C function? d) Left to write of the expression
View Answer
1. #include <stdio.h>
2. int main()
3. { 4. What will be the final values of i and j in
4. reverse(1); the following C code?
5. }
6. void reverse(int i) 1. #include <stdio.h>
7. { 2. int x = 0;
8. if (i > 5) 3. int main()
9. exit(0); 4. {
10. printf("%d\n", i); 5. int i = (f() + g()) ||
11. return reverse(i++); g();
12. } 6. int j = g() || (f() +
g());
a) 1 2 3 4 5 7. }
b) 1 2 3 4 8. int f()
9. {
c) Compile time error 10. if (x == 0)
d) Stack overflow 11. return x + 1;
View Answer 12. else
13. return x - 1;
14. }
2. What will be the output of the following 15. int g()
C function? 16. {
17. return x++;
1. #include <stdio.h> 18. }
2. void reverse(int i);
3. int main()
4. {
a) i value is 1 and j value is 1
5. reverse(1); b) i value is 0 and j value is 0
6. } c) i value is 1 and j value is undefined
7. void reverse(int i) d) i and j value are undefined
8. { View Answer
9. if (i > 5)
10. return ;
11. printf("%d ", i); 5. What will be the final values of i and j in
12. return reverse((i++, the following C code?
i));
13. } 1. #include <stdio.h>
2. int x = 0;
a) 1 2 3 4 5 3. int main()
b) Segmentation fault 4. {
5. int i = (f() + g()) |
c) Compilation error g(); //bitwise or
6. int j = g() | (f() + 6. printf("%d\n", z);
g()); //bitwise or 7. return 0;
7. } 8. }
8. int f()
9. { a) 0
10. if (x == 0)
11. return x + 1; b) 1
12. else c) 2
13. return x - 1; d) Undefined behaviour
14. } View Answer
15. int g()
16. {
17. return x++; 8. What will be the output of the following
18. } C code?

a) i value is 1 and j value is 1 1. #include <stdio.h>


b) i value is 0 and j value is 0 2. int main()
3. {
c) i value is 1 and j value is undefined 4. int x = 2, y = 0;
d) i and j value are undefined 5. int z;
View Answer 6. z = (y++, y);
7. printf("%d\n", z);
8. return 0;
6. What will be the output of the following 9. }
C code?
a) 0
1. #include <stdio.h>
2. int main() b) 1
3. { c) Undefined behaviour
4. int x = 2, y = 0; d) Compilation error
5. int z = y && (y |= View Answer
10);
6. printf("%d\n", z);
7. return 0; 9. What will be the output of the following
8. } C code?

a) 1 1. #include <stdio.h>
b) 0 2. int main()
3. {
c) Undefined behaviour due to order of 4. int x = 2, y = 0, l;
evaluation 5. int z;
d) 2 6. z = y = 1, l = x && y;
View Answer 7. printf("%d\n", l);
8. return 0;
9. }
7. What will be the output of the following
C code? a) 0
b) 1
advertisement
c) Undefined behaviour due to order of
1. #include <stdio.h> evaluation can be different
2. int main() d) Compilation error
3. { View Answer
4. int x = 2, y = 0;
5. int z = (y++) ? 2 : y
== 1 && x;
10. What will be the output of the following c) compile time error
C code? d) undefined behaviour
View Answer
1. #include <stdio.h>
2. int main() 3. What will be the output of the following
3. {
4. int y = 2; C code?
5. int z = y +(y = 10);
6. printf("%d\n", z); 1. #include <stdio.h>
7. } 2. int main()
3. {
4. int x = 1, y = 2;
a) 12 5. int z = x & y == 2;
b) 20 6. printf("%d\n", z);
c) 4 7. }
d) Either 12 or 20
a) 0
1. What will be the output of the following b) 1
C code? c) Compile time error
d) Undefined behaviour
1. #include <stdio.h> View Answer
2. int main()
3. {
4. int x = 2, y = 2; 4. What will be the output of the following
5. float f = y + x /= x / C code?
y;
6. printf("%d %f\n", x, 1. #include <stdio.h>
f); 2. int main()
7. return 0; 3. {
8. } 4. int x = 3, y = 2;
5. int z = x /= y %= 2;
a) 2 4.000000 6. printf("%d\n", z);
7. }
b) Compile time error
c) 2 3.500000
a) 1
d) Undefined behaviour
b) Compile time error
View Answer
c) Floating point exception
d) Segmentation fault
2. What will be the output of the following
View Answer
C code?

1. #include <stdio.h> 5. What will be the output of the following


2. int main() C code?
3. {
4. int x = 1, y = 2; 1. #include <stdio.h>
5. if (x && y == 1) 2. int main()
6. printf("true\n"); 3. {
7. else 4. int x = 3, y = 2;
8. printf("false\n"); 5. int z = x << 1 > 5;
9. } 6. printf("%d\n", z);
7. }
a) true
b) false
a) 1 4. int x = 2, y = 0;
b) 0 5. int z = x && y = 1;
6. printf("%d\n", z);
c) 3 7. }
d) Compile time error
View Answer a) 0
b) 1
6. What will be the output of the following c) Compile time error
C code? d) 2
View Answer
1. #include <stdio.h>
2. int main()
3. { 9. What will be the output of the following
4. int x = 3; //, y = 2; C code?
5. const int *p = &x;
6. *p++; 1. #include <stdio.h>
7. printf("%d\n", *p); 2. int main()
8. } 3. {
4. int x = 0, y = 2;
a) Increment of read-only location compile 5. if (!x && y)
error 6. printf("true\n");
7. else
b) 4 8. printf("false\n");
c) Some garbage value 9. }
d) Undefined behaviour
View Answer a) True
b) False
advertisement c) Compile time error
d) Undefined behaviour
7. What will be the output of the following View Answer
C code?
10. What will be the output of the following
1. #include <stdio.h>
2. int main()
C code?
3. {
4. int x = 2, y = 2; 1. #include <stdio.h>
5. int z = x ^ y & 1; 2. int main()
6. printf("%d\n", z); 3. {
7. } 4. int x = 0, y = 2;
5. int z = ~x & y;
6. printf("%d\n", z);
a) 1 7. }
b) 2
c) 0 a) -1
d) 1 or 2 b) 2
View Answer c) 0
d) Compile time error
8. What will be the output of the following
C code? 1. What will be the output of the following
C code?
1. #include <stdio.h>
2. int main()
1. #include <stdio.h>
3. {
2. void main() 2. void main()
3. { 3. {
4. int a = 5 * 3 + 2 - 4; 4. int b = 6;
5. printf("%d", a); 5. int c = 7;
6. } 6. int a = ++b + c--;
7. printf("%d", a);
8. }
a) 13
b) 14
c) 12 a) Run time error
d) 1 6 b) 15
View Answer c) 13
d) 14
2. What will be the output of the following View Answer
C code?
5. What will be the output of the following
1. #include <stdio.h> C code?
2. void main()
3. { 1. #include <stdio.h>
4. int a = 2 + 4 + 3 * 5 2. void main(
/ 3 - 5; 3. {
5. printf("%d", a); 4. double b = 8;
6. } 5. b++;
6. printf("%lf", b);
7. }
a) 7
b) 6
c) 10 a) 9.000000
d) 9 b) 9
View Answer c) 9.0
d) Run time error
3. What will be the output of the following View Answer
C code?
6. What will be the output of the following
1. #include <stdio.h> C code?
2. void main()
3. { 1. #include <stdio.h>
4. int a = 5 * 3 % 6 - 8 2. void main()
+ 3; 3. {
5. printf("%d", a); 4. double b = 3 % 0 * 1 -
6. } 4 / 2;
5. printf("%lf", b);
a) 10 6. }
b) 2
c) -2 a) -2
d) -3 b) Floating point Exception
View Answer c) 1
d) None of the mentioned
4. What will be the output of the following View Answer
C code?
advertisement
1. #include <stdio.h>
7. What will be the output of the following 10. What will be the output of the following
C code? C code?

1. #include <stdio.h> 1. #include <stdio.h>


2. void main() 2. void main()
3. { 3. {
4. double b = 5 % 3 & 4 + 4. int k = 0;
5 * 6; 5. double b = k++ + ++k +
5. printf("%lf", b); k--;
6. } 6. printf("%d", k);
7. }
a) 2
b) 30 a) 6
c) 2.000000 b) 1
d) Run time error c) 5
View Answer d) undefined

8. What will be the output of the following 1. What will be the output of the following
C code? C code?

1. #include <stdio.h> 1. #include <stdio.h>


2. void main() 2. void main()
3. { 3. {
4. double b = 3 && 5 & 4 4. int b = 5 - 4 + 2 * 5;
% 3; 5. printf("%d", b);
5. printf("%lf", b); 6. }
6. }
a) 25
a) 3.000000 b) -5
b) 4.000000 c) 11
c) 5.000000 d) None of the mentioned
d) 1.000000 View Answer
View Answer
2. What will be the output of the following
9. What will be the output of the following C code?
C code?
1. #include <stdio.h>
1. #include <stdio.h> 2. void main()
2. void main() 3. {
3. { 4. int b = 5 & 4 & 6;
4. double b = 5 & 3 && 4 5. printf("%d", b);
|| 5 | 6; 6. }
5. printf("%lf", b);
6. } a) 5
b) 6
a) 1.000000 c) 3
b) 0.000000 d) 4
c) 7.000000 View Answer
d) 2.000000
View Answer
3. What will be the output of the following 6. What will be the output of the following
C code? C code?

1. #include <stdio.h> 1. #include <stdio.h>


2. void main() 2. void main()
3. { 3. {
4. int b = 5 & 4 | 6; 4. int h = 8;
5. printf("%d", b); 5. int b = h++ + h++ +
6. } h++;
6. printf("%d\n", h);
7. }
a) 6
b) 4
c) 1 a) 9
d) 0 b) 10
View Answer c) 12
d) 11
4. What will be the output of the following View Answer
C code?
advertisement
1. #include <stdio.h>
2. void main() 7. What will be the output of the following
3. { C code?
4. int b = 5 + 7 * 4 - 9
* (3, 2); 1. #include <stdio.h>
5. printf("%d", b); 2. void main()
6. } 3. {
4. int h = 8;
a) 6 5. int b = 4 * 6 + 3 * 4
b) 15 < 3 ? 4 : 3;
6. printf("%d\n", b);
c) 13 7. }
d) 21
View Answer a) 3
b) 33
5. What will be the output of the following c) 34
C code? d) Run time error
View Answer
1. #include <stdio.h>
2. void main()
3. { 8. What will be the output of the following
4. int h = 8; C code?
5. int b = (h++, h++);
6. printf("%d%d\n", b, 1. #include <stdio.h>
h); 2. void main()
7. } 3. {
4. int a = 2 + 3 - 4 + 8
a) 10 10 - 5 % 4;
b) 10 9 5. printf("%d\n", a);
6. }
c) 9 10
d) 8 10
a) 0
View Answer
b) 8
c) 11 2. Which operators of the following have
d) 9 same precedence?
View Answer
P. "!=", Q. "+=", R. "<<="
9. What will be the output of the following
C code? a) P and Q
b) Q and R
1. #include <stdio.h> c) P and R
2. void main() d) P, Q and R
3. { View Answer
4. char a = '0';
5. char b = 'm';
6. int c = a && b || '1'; 3. Comment on the following statement.
7. printf("%d\n", c);
8. } n = 1;
printf("%d, %dn", 3*n, n++);
a) 0
b) a a) Output will be 3, 2
c) 1 b) Output will be 3, 1
d) m c) Output will be 6, 1
View Answer d) Output is compiler dependent
View Answer
10. What will be the output of the following
C code? 4. Which of the following option is the
correct representation of the following C
1. #include <stdio.h> statement?
2. void main()
3. { e = a * b + c / d * f;
4. char a = 'A';
5. char b = 'B';
6. int c = a + b % 3 - 3 a) e = (a * (b +(c /(d * f))));
* 2; b) e = ((a * b) + (c / (d * f)));
7. printf("%d\n", c); c) e = ((a * b) + ((c / d)* f));
8. } d) Both e = ((a * b) + (c / (d * f))); and e =
((a * b) + ((c / d)* f));
a) 65 View Answer
b) 58
c) 64 5. While swapping 2 numbers what
d) 59 precautions to be taken care?
1. Which of the following operators has an b = (b / a);
associativity from Right to Left? a = a * b;
a) <= b = a / b;
b) <<
c) == a) Data type should be either of short, int
d) += and long
View Answer b) Data type should be either of float and
double
c) All data types are accepted except for
(char *)
d) This code doesn’t swap 2 numbers a) ()
View Answer b) sizeof
c) *
advertisement d) +
View Answer
6. What will be the output of the following
C code? 10. Which of the following is a ternary
operator?
1. #include<stdio.h> a) &&
2. int main()
3. { b) >>=
4. int a = 1, b = 2, c = c) ?:
3, d = 4, e; d) ->
5. e = c + d = b * a;
6. printf("%d, %d\n", e,
1. Which of the following are unary
d);
7. } operators?
a) sizeof
a) 7, 4 b) –
b) 7, 2 c) ++
c) 5, 2 d) all of the mentioned
d) Syntax error View Answer
View Answer
2. Where in C the order of precedence of
7. Which of the following is the correct operators do not exist?
order of evaluation for the given expression? a) Within conditional statements, if, else
b) Within while, do-while
a = w % x / y * z; c) Within a macro definition
d) None of the mentioned
a) % / * = View Answer
b) / * % =
c) = % * / 3. Associativity of an operator is
d) * % / = ___________
View Answer a) Right to Left
b) Left to Right
8. Which function in the following c) Random fashion
expression will be called first? d) Both Right to Left and Left to Right
View Answer
a = func3(6) - func2(4, 5) /
func1(1, 2, 3); 4. Which of the following method is
accepted for assignment?
a) func1(); a) 5 = a = b = c = d;
b) func2(); b) a = b = c = d = 5;
c) func3(); c) a = b = 5 = c = d;
d) Cannot be predicted d) None of the mentioned
View Answer View Answer

9. Which of the following operator has the


highest precedence in the following?
5. Which of the following is NOT possible 1. #include <stdio.h>
with any 2 operators in C? 2. int main()
3. {
a) Different precedence, same associativity 4. int a = -1, b = 4, c =
b) Different precedence, different 1, d;
associativity 5. d = ++a && ++b || ++c;
c) Same precedence, different associativity 6. printf("%d, %d, %d,
%d\n", a, b, c, d);
d) All of the mentioned 7. return 0;
View Answer 8. }

6. Which of the following is possible with a) 0, 4, 2, 1


any 2 operators in C? b) 0, 5, 2, 1
a) Same associativity, different precedence c) -1, 4, 1, 1
b) Same associativity, same precedence d) 0, 5, 1, 0
c) Different associativity, different View Answer
precedence
d) All of the mentioned advertisement
View Answer
10. What will be the output of the following
7. Which of the following operators has the C code?
lowest precedence?
a) != 1. #include <stdio.h>
b) && 2. int main()
3. {
c) ?: 4. int p = 10, q = 20, r;
d) , 5. if (r = p = 5 || q >
View Answer 20)
6. printf("%d", r);
7. else
8. What will be the output of the following
8. printf("No
C code? Output\n");
9. }
1. #include <stdio.h>
2. int main()
3. {
a) 1
4. int x = 3, i = 0; b) 10
5. do { c) 20
6. x = x++; d) No Output
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

9. What will be the output of the following


C code?

Вам также может понравиться