Você está na página 1de 17

Max qs = 30 Time = 60 mins

Arithmetic operator

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


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

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
3. What will be the output of the following C code?
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

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


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

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


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
7. What will be the output of the following C code?
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
Bitwise Operator

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


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

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

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


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

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


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

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);

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

7. a = a * 2;

8. }

a) Logical Shift left


b) No output
c) Arithmetic Shift right
d) Bitwise exclusive OR

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


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

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

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;

6. int *k = p++;

7. int r = p - k;

8. printf("%d", r);

9. }

a) 4
b) 8
c) 1
d) Run time error
Declaration

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


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

a) Compile time error


b) 10 20
c) Undefined value
d) 10

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


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

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


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
d) 0
View Answer
4. Will the following C code compile without any error?
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) None of the mentioned
advertisement

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

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


a) String str;
b) char *str;
c) float str = 3e2;
d) Both String str; & float str = 3e2;
View Answer
7. Which of the following format identifier can never be used for the variable var?
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

increment decrement operator

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


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
2. What will be the output of the following C code?
1. #include <stdio.h>

2. int main()

3. {

4. int i = 10;

5. int *p = &i;

6. printf("%d\n", *p++);

7. }

a) 10
b) 11
c) Garbage value
d) Address of i

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


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
4. 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 3 3
c) 3 2 2
d) 2 3 4

5. 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;

6. int *k = p++;

7. int r = p - k;

8. printf("%d", r);

9. }

a) 4
b) 8
c) 1
d) Run time error

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


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

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
Data Type

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


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
2. The format identifier ‘%i’ is also used for _____ data type.
a) char
b) int
c) float
d) double

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
d) int

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
5. What is the size of an int data type?
a) 4 Bytes
b) 8 Bytes
c) Depends on the system/compiler
d) Cannot be determined

6. What is the output of the following C code?


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

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

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

Você também pode gostar