BIG-D Computer Programming5
BIG-D Computer Programming5
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()
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?
1. #include <stdio.h>
2. void main()
3. {
4. int x = 5;
5. if (true);
6. printf("hello");
7. }
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?
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.
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. }
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) 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)
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");
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.
28. When a C program is started, O.S environment is responsible for opening file and
providing pointer for that file?
a) Standard input
b) Standard output
c) Standard error
d) All of the mentioned
View Answer
Answer: d
Explanation: None.
29. In C language, FILE is of which data type?
a) int
b) char *
c) struct
d) None of the mentioned
View Answer
Answer: c
Explanation: None.
30. What is the sizeof(char) in a 32-bit C compiler?
a) 1 bit
b) 2 bits
c) 1 Byte
d) 2 Bytes
View Answer
Answer: c
Explanation: None.
31. Which of the following is not an operator in C?
a) ,
b) sizeof()
c) ~
d) None of the mentioned
View Answer
Answer: d
Explanation: None.
32. scanf() is a predefined function in______header file.
a) stdlib. h
b) ctype. h
c) stdio. h
d) stdarg. h
View Answer
Answer: c
Explanation: scanf() is a predefined function in "stdio.h" header file.printf and scanf()
carry out input and output functions in C. These functions statements are present in the
header file stdio.h.
fp = fopen("Random.txt", "a");
a) Attach
b) Append
c) Apprehend
d) Add
View Answer
Answer: b
Explanation: None.
34. What will be the output of the following C code?
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
1. #include <stdio.h>
2. int main()
3. {
4. int main = 3;
5. printf("%d", main);
6. return 0;
7. }
a) 128
b) -128
c) Depends on the compiler
d) None of the mentioned
View Answer
Answer: b
Explanation: The range of signed character is from -128 to +127. Since we are assigning
a value of 128 to the variable ‘chr’, the result will be negative. 128 in binary is
represented as “1000 0000” for character datatype. As you can see that the sign bit is
set to 1, followed by 7 zeros (0), its final decimal value will be -128 (negative 128).
Output:
$ cc pgm2.c
$ a.out
-128
37. What will be the output of the following C code on a 64 bit machine?
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
38. 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
39. What will be the output of the following C code?
1. #include <stdio.h>
2. int const print()
3. {
4. printf("Sanfoundry.com");
5. return 0;
6. }
7. void main()
8. {
9. print();
10. }
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
41. 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.
42. What will be the output of the following C code? (Initial values: x= 7, y = 8)
1. #include <stdio.h>
2. void main()
3. {
4. float x;
5. int y;
6. printf("enter two numbers \n");
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.
43. 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?
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.
44. What is the difference between the following 2 C codes?
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.
46. What will be the value of the following assignment expression?
a) 2
b) True
c) 1
d) 0
View Answer
Answer: a
Explanation: None.
47. 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
Answer: a
Explanation: None.
48. 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 f()
4.{
5. if (x == 0)
6. return x + 1;
7. else
8. return x - 1;
9.}
10. int g()
11. {
12. return x++;
13. }
14. int main()
15. {
16. int i = (f() + g()) | g(); //bitwise or
17. int j = g() | (f() + g()); //bitwise or
18. }
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.
50. How many times i value is checked in the following C program?
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.
51. What will be the output of the following C code?
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.
52. 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
Answer: b
Explanation: None.
53. What is the problem in the following C declarations?
int func(int);
double func(int);
int func(float);
string p = "HELLO";
printf(“%10s”, state);
a) 5, 5, 5, 5, 5
b) 5, 0, 0, 0, 0
c) 5, (garbage), (garbage), (garbage), (garbage)
d) (garbage), (garbage), (garbage), (garbage), 5
View Answer
Answer: b
Explanation: None.
57. What will be the output of the following C function when EOF returns?
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.
59. Which of the following sequences are unaccepted in C language?
a)
#if
#else
#endif
b)
#if
#elif
#endif
c)
#if
#if
#endif
d)
#if
#undef
#endif
View Answer
Answer: c
Explanation: None.
1. #include <stdio.h>
2. main()
3. {
4. char *p = 0;
5. *p = 'a';
6. printf("value in pointer p is %c\n", *p);
7. }
a) It will print a
b) It will print 0
c) Compile time error
d) Run time error
View Answer
Answer:d
Output:
$ cc pgm.c
$ a.out
Segmentation fault (core dumped)
60. What is the output of this C code?
1. #include <stdio.h>
2. main()
3. {
4. if (sizeof(int) > -1)
5. printf("True");
6. else
7. printf("False");
8. }
a) True
b) False
View Answer
Answer:b
Output:
$ cc pgm.c
$ a.out
False
61. What is the output of this C code?
1. #include <stdio.h>
2. main()
3. {
4. char *p = "Sanfoundry C-Test";
5. p[0] = 'a';
6. p[1] = 'b';
7. printf("%s", p);
8. }
a) abnfoundry C-Test
b) Sanfoundry C-Test
c) Compile time error
d) Run time error
View Answer
Answer:d
Output:
$ cc pgm.c
$ a.out
Segmentation fault (core dumped)
62. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. float f = 0.1;
5. if (f == 0.1)
6. printf("True");
7. else
8. printf("False");
9. }
a) True
b) False
View Answer
Answer: b
Output:
$ cc pgm.c
$ a.out
False
63. What is the output of this C code?
1. #include <stdio.h>
2. main()
3. {
4. int n = 0, m = 0;
5. if (n > 0)
6. if (m > 0)
7. printf("True");
8. else
9. printf("False");
10. }
a) True
b) False
c) No Output will be printed
d) Run Time Error
View Answer
Answer:c
Output:
$ cc pgm.c
$ a.out
$