Download - ACP MCQ.docx
-
8/10/2019 ACP MCQ.docx
1/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
1. The following code for(;;) represents an infinite loop. It can be terminated by.
a) break
b) exit(0)
c) abort()d) All of the mentioned
Answer:a
2. The correct syntax for running two variable for loop simultaneously is.
a) for (i = 0; i < n; i++)
for (j = 0; j < n; j += 5)b) for (i = 0, j = 0;i < n, j < n; i++, j += 5)
c) for (i = 0; i < n;i++){}
for (j = 0; j < n;j += 5){}
d) None of the mentionedAnswer:b
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)
Answer:d
4. Which of the following cannot be used as LHS of the expression in for (exp1;exp2; exp3) ?
a) Variable
b) Functionc) typedef
d) macrosAnswer:d
5. What is the output of this C code?
1. #include
2. int main()
3. {4. short i;
5. for (i = 1; i >= 0; i++)
6. printf("%d\n", i);
7.8. }
a) The control wont fall into the for loopb) 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 errorsAnswer:c
-
8/10/2019 ACP MCQ.docx
2/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
6. What is the output of this C code?
1. #include 2. void main()
3. {
4.
int k = 0;5. for (k)6. printf("Hello");
7. }
a) Compile time error
b) hello
c) Nothingd) Varies
Answer:a
7. What is the output of this C code?
1. #include 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 thricec) Nothing
d) Varies
Answer:a
8. What is the output of this C code?
1. #include
2. void main()
3. {
4. double k = 0;
5.
for (k = 0.0; k < 3.0; k++)6. printf("Hello");
7. }
a) Run time errorb) Hello is printed thrice
c) Hello is printed twice
d) Hello is printed infinitely
Answer:b
-
8/10/2019 ACP MCQ.docx
3/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
1. What is the output of this C code?
1. #include 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.000000d) Run time error
Answer:c
2. What is the output of this C code?
1. #include 2. void main()
3. {
4. int k;5. for (k = -3; k < -5; k++)
6. printf("Hello");
7. }
a) Hello
b) Infinite helloc) Run time error
d) Nothing
Answer:d
3. What is the output of this C code?
1. #include
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
-
8/10/2019 ACP MCQ.docx
4/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
d) Undefined behaviour
Answer:a
4. What is the output of this C code?
1.
#include 2. int main()
3. {
4. int i = 0;5. for (i++; i == 1; i = 2)
6. printf("In for loop ");
7. printf("After loop\n");
8. }
a) In for loop after loopb) After loop
c) Compile time errord) Undefined behaviour
Answer:a
5. What is the output of this C code?
1. #include
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 loopb) In for loop after loop
c) Compile time error
d) Infinite loopAnswer:a
6. What is the output of this C code?
1. #include
2. int main()
3. {
4. int *p = NULL;
-
8/10/2019 ACP MCQ.docx
5/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
5. for (foo(); p; p = 0)
6. printf("In for loop\n");
7. printf("After loop\n");
8. }
a) In for loop after loopb) Compile time errorc) Infinite loop
d) Depends on the value of NULL
Answer:b
7. What is the output of this C code?
1. #include
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 loopc) Depends on the standard compiler implements
d) Depends on the compiler
Answer:c
1. What is the output of this C code?
1. #include
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 errord) Infinite loop
Answer:c
2. What is the output of this C code?
1. #include
2. int main()3. {
-
8/10/2019 ACP MCQ.docx
6/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
4. do
5. printf("In while loop ");
6. while (0);
7. printf("After loop\n");8. }
a) In while loopb) In while loop
after loop
c) After loopd) Infinite loop
Answer:b
3. What is the output of this C code?
1. #include
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 loopIn while loop
In while loopb) In while loopIn while loop
c) Depends on the compiler
d) Compile time errorAnswer:a
4. How many times i value is checked in the below code?
1. #include
2. int main()
3.
{4. int i = 0;
5. do {
6. i++;7. printf("in while loop\n");
8. } while (i < 3);
9. }
-
8/10/2019 ACP MCQ.docx
7/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
a) 2
b) 3
c) 4
d) 1Answer:b
5. How many times i value is checked in the below code?
1. #include 2. int main()
3. {
4. int i = 0;
5. while (i < 3)6. i++;
7. printf("In while loop\n");
8. }
a) 2b) 3c) 4
d) 1
6. What is the output of this C code?
1. #include
2. void main()
3. {4. int i = 2;
5.
do6. {7. printf("Hi");
8. } while (i < 2)
9. }
a) Compile time error
b) Hi Hic) Hi
d) Varies
Answer:a
7. What is the output of this C code?
1. #include
2. void main()
3. {4. int i = 0;
5. while (++i)
6. {
-
8/10/2019 ACP MCQ.docx
8/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
7. printf("H");
8. }
9. }
a) H
b) H is printed infinite timesc) Compile time errord) Varies
Answer:b
8. What is the output of this C code?
1. #include 2. void main()
3. {
4. int i = 0;
5.
do6. {
7. printf("Hello");8. } while (i != 0);
9. }
a) Nothing
b) H is printed infinite times
c) Hello
d) Run time errorAnswer:c
-
8/10/2019 ACP MCQ.docx
9/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
1. What is the output of this C code?
1. #include 2. void main()
3. {
4.
char *str = "";5. do6. {
7. printf("hello");
8. } while (str);9. }
a) Nothingb) Run time error
c) Varies
d) Hello is printed infinite times
Answer:d
2. What is the output of this C code?
1. #include
2. void main()3. {
4. int i = 0;
5. while (i < 10)
6. {7. i++;
8.
printf("hi\n");9. } while (i < 8)10. i++;
11. printf("hello\n");
12. }
a) Hi is printed 8 times, hello 7 times and then hi 2 times
b) Hi is printed 10 times, hello 7 timesc) Hi is printed once, hello 7 times
d) Hi is printed once, hello 7 times and then hi 2 times
Answer:d
3. Example of iteration in C.
a) for
b) whilec) do-while
d) All of the mentioned
Answer:d
-
8/10/2019 ACP MCQ.docx
10/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
4. Number of times while loop condition is tested is, i is initialized to 0 in both case.
while (i < n)
i++;
-------------do
i++;while (i
-
8/10/2019 ACP MCQ.docx
11/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
d) Syntax error
Answer:c
7. Which loop is most suitable to first perform the operation and then test the condition?
a) for loop
b) while loopc) do-while loopd) None of the mentioned
Answer:c
1. The output of the code below is
1. #include 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) helloc) no
d) None of the mentionedAnswer:a
2. The output of the code below is
1. #include
2. int x;3. void main()
4. {
5. if (x)
6. printf("hi");
7.
else8. printf("how are u");
9. }
a) hi
b) how are youc) Compile time error
d) None of the mentioned
Answer:b
-
8/10/2019 ACP MCQ.docx
12/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
3. Comment on the following code below
1. #include 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 displayedd) Compiler dependent
Answer:b
4. The output of the code below is
1. #include 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 youc) hello
d) hihello
Answer:d
5. The output of the code below is
1. #include
2.
void main()3. {
4. int x = 5;5. if (x < 1);
6. printf("Hello");
7.8. }
-
8/10/2019 ACP MCQ.docx
13/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
a) Nothing
b) Run time error
c) Hello
d) VariesAnswer:c
6. The output of the code below is(when 1 is entered)
1. #include 2. void main()
3. {
4. double ch;
5. printf("enter a value btw 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 errorb) 1
c) 2d) Varies
Answer:a
7. The output of the code below is(When 1 is entered)
1. #include
2. void main()3. {
4. char *ch;
5. printf("enter a value btw 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;
-
8/10/2019 ACP MCQ.docx
14/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
15. }
16. }
a) 1b) 2
c) Compile time errord) No Compile time errorAnswer:c
8. When 1 is entered, The output of the code below is?
1. #include 2. void main()3. {
4. int ch;
5. printf("enter a value btw 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) 2c) 1 2d) Run time error
Answer:c
9. When 2 is entered, The output of the code below is?
1. #include
2. void main()
3. {
4. int ch;
5.
printf("enter a value btw 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:
-
8/10/2019 ACP MCQ.docx
15/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
14. printf("2\n");
15. }
16. }
a) 1
b) Hi 2c) Run time errord) 2
Answer:d
10. When 1 is entered, The output of the code below is?
1. #include 2. void main()
3. {
4. int ch;
5.
printf("enter a value btw 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) 3d) Run time error
Answer:b
1. What is the output of this C code?
1. #include
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. }
-
8/10/2019 ACP MCQ.docx
16/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
a) inside if
b) inside elseif
c) inside if
inside elseifd) Compile time error
Answer:a
2. What is the output of this C code?
1. #include
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) trueb) false
c) Compile time error
d) Undefined behaviourAnswer:b
3. What is the output of this C code?
1.
#include 2. int main()
3. {
4. int x = 0;5. if (x == 1)
6. if (x == 0)
7. printf("inside if\n");
8. else9. printf("inside else if\n");
10. else
11. printf("inside else\n");
12.
}
a) inside ifb) inside else ifc) inside else
d) Compile time error
Answer:c
4. What is the output of this C code?
-
8/10/2019 ACP MCQ.docx
17/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
1. #include
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, 10d) Compile time error
Answer:b
5. What is the output of this C code?
1. #include
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) falsec) Depends on the compiler
d) No print statement
Answer:d
6. if (a == 1||b == 2){} can be written as:
a) 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
Answer:d
-
8/10/2019 ACP MCQ.docx
18/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
7. Which of the following is an invalid if-else statement?
a) if (if (a == 1)){}
b) if (func1 (a)){}
c) if (a){}d) if ((char) a){}
Answer:a
8. What is the output of this C code?
1. #include
2. int main()
3. {
4. int a = 1;5. if (a--)
6. printf("True");
7. if (a++)
8.
printf("False");9. }
a) Trueb) False
c) True False
d) No OutputAnswer:a
9. Comment on the output of this C code?
1.
#include 2. int main()
3. {
4. int a = 1;5. if (a)
6. printf("All is Well ");
7. printf("I am Well\n");
8. else9. printf("I am not a River\n");
10. }
a) Output will be All is Well I am Wellb) Output will be I am Well I am not a River
c) Output will be I am Well
d) Compile time errors during compilationAnswer:d
10. What is the output of this C code?
1. #include
-
8/10/2019 ACP MCQ.docx
19/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
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 Happyb) 1We are Happyc) 1We are Sad
d) Compile time error
Answer:d
1. What is the output of this C code?
1. #include 2. int main()
3. {
4. char *p = NULL;5. char *q = 0;
6. if (p)
7. printf(" p ");
8. else9. printf("nullp");
10.
if (q)11. printf("q\n");12. else
13. printf(" nullq\n");
14. }
a) nullp nullq
b) Depends on the compilerc) x nullq where x can be p or nullp depending on the value of NULL
d) p q
2. What is the output of this C code?
1. #include
2. int main()3. {4. int i = 10;
5. void *p = &i;
6. printf("%d\n", (int)*p);7. return 0;
8. }
-
8/10/2019 ACP MCQ.docx
20/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
a) Compile time error
b) Segmentation fault/runtime crash
c) 10
d) Undefined behaviour3. What is the output of this C code?
1. #include 2. int main()
3. {
4. int i = 10;5. void *p = &i;
6. printf("%f\n", *(float*)p);
7. return 0;
8. }
a) Compile time error
b) Undefined behaviourc) 10
d) 0.000000
Answer:d
4. What is the output of this C code?
1. #include
2. int *f();
3. int main()4. {
5.
int *p = f();6. printf("%d\n", *p);7. }
8. int *f()
9. {10. int *j = (int*)malloc(sizeof(int));
11. *j = 10;
12. return j;13. }
a) 10
b) Compile time errorc) Segmentation fault/runtime crash since pointer to local variable is returned
d) Undefined behaviour
Answer:a
5. What is the output of this C code?
1. #include
2. int *f();
-
8/10/2019 ACP MCQ.docx
21/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
3. int main()
4. {
5. int *p = f();
6. printf("%d\n", *p);7. }
8.
int *f()9. {10. int j = 10;
11. return &j;12. }
a) 10
b) Compile time error
c) Segmentation fault/runtime crashd) Undefined behaviour
Answer:a
6. Comment on the following pointer declaration?
int *ptr, p;
a) ptr is a pointer to integer, p is notb) ptr and p, both are pointers to integer
c) ptr is a pointer to integer, p may or may not be
d) ptr and p both are not pointers to integerAnswer:a
7. What is the output of this C code?
1.
#include 2. int main()3. {
4. int *ptr, a = 10;
5. ptr = &a;6. *ptr += 1;
7. printf("%d,%d/n", *ptr, a);
8. }
a) 10,10
b) 10,11
c) 11,10d) 11,11
Answer:d
8. Comment on the following?
const int *ptr;
a) You cannot change the value pointed by ptrb) You cannot change the pointer ptr itself
c) Both (a) and (b)
-
8/10/2019 ACP MCQ.docx
22/40
-
8/10/2019 ACP MCQ.docx
23/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
a) 0 1
b) Compile time error
c) 0xbfd605e8 0xbfd605ec
d) 0xbfd605e8 0xbfd605e8Answer:b
5. What is the output of this C code?
1. #include 2. void main()
3. {
4. int x = 0;
5. int *ptr = &x;6. printf("%p\n", ptr);
7. ptr++;
8. printf("%p\n ", ptr);
9.
}
a) 0xbfd605e8 0xbfd605ecb) 0xbfd605e8 0cbfd60520
c) 0xbfd605e8 0xbfd605e9
d) Run time error
Answer:a
6. What is the output of this C code?
1. #include
2.
void main()3. {
4. int x = 0;
5. int *ptr = &5;6. printf("%p\n", ptr);
7. }
a) 5b) Address of 5
c) Nothing
d) Compile time error
Answer:d
7. What is the output of this C code?
1. #include 2. void main()
3. {
4. int x = 0;
5. int *ptr = &x;
-
8/10/2019 ACP MCQ.docx
24/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
6. printf("%d\n", *ptr);
7. }
a) Address of xb) Junk value
c) 0d) Run time errorAnswer:c
1. What is the output of this C code?
1. #include 2. void foo(int*);3. int main()
4. {
5. int i = 10;
6.
foo((&i)++);7. }
8. void foo(int *p)9. {
10. printf("%d\n", *p);
11. }
a) 10
b) Some garbage value
c) Compile time errord) Segmentation fault/code crash
Answer:c
2. What is the output of this C code?
1. #include
2. void foo(int*);
3. int main()4. {
5. int i = 10, *p = &i;
6. foo(p++);
7. }
8.
void foo(int *p)9. {
10. printf("%d\n", *p);
11. }
a) 10b) Some garbage value
c) Compile time error
-
8/10/2019 ACP MCQ.docx
25/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
d) Segmentation fault
Answer:a
3. What is the output of this C code?
1.
#include 2. void foo(float *);
3. int main()
4. {5. int i = 10, *p = &i;
6. foo(&i);
7. }
8. void foo(float *p)9. {
10. printf("%f\n", *p);
11. }
a) 10.000000b) 0.000000c) Compile time error
d) Undefined behaviour
Answer:b
4. What is the output of this C code?
1. #include
2. int main()
3.
{4. int i = 97, *p = &i;
5. foo(&i);
6. printf("%d ", *p);7. }
8. void foo(int *p)
9. {
10. int j = 2;11. p = &j;
12. printf("%d ", *p);
13. }
a) 2 97b) 2 2
c) Compile time errord) Segmentation fault/code crash
Answer:a
5. What is the output of this C code?
-
8/10/2019 ACP MCQ.docx
26/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
1. #include
2. int main()
3. {
4. int i = 97, *p = &i;5. foo(&p);
6.
printf("%d ", *p);7. return 0;8. }
9. void foo(int **p)10. {
11. int j = 2;12. *p = &j;
13. printf("%d ", **p);
14. }
a) 2 2
b) 2 97c) Undefined behaviour
d) Segmentation fault/code crash
Answer:a
6. What is the output of this C code?
1. #include
2. int main()
3. {4. int i = 11;
5.
int *p = &i;6. foo(&p);
7. printf("%d ", *p);8. }
9. void foo(int *const *p)
10. {11. int j = 10;
12. *p = &j;
13. printf("%d ", **p);14. }
a) Compile time errorb) 10 10
c) Undefined behaviour
d) 10 11
Answer:a
7. What is the output of this C code?
1. #include
-
8/10/2019 ACP MCQ.docx
27/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
2. int main()
3. {
4. int i = 10;
5. int *p = &i;6. foo(&p);
7.
printf("%d ", *p);8. printf("%d ", *p);9. }
10. void foo(int **const p)11. {
12. int j = 11;13. *p = &j;
14. printf("%d ", **p);
15. }
a) 11 11 11
b) 11 11 Undefined-valuec) Compile time error
d) Segmentation fault/code-crash
Answer:b
8. What is the output of the code below?
1. #include
2. int main()
3. {4. int i = 10;
5.
int *const p = &i;6. foo(&p);
7. printf("%d\n", *p);8. }
9. void foo(int **p)
10. {11. int j = 11;
12. *p = &j;
13. printf("%d\n", **p);14. }
a) 11 11b) Undefined behaviour
c) Compile time error
d) Segmentation fault/code-crash
Answer:a
9. Which of the following are correct syntaxes to send an array as a parameter to function:a) func(&array);
b) func(array);
-
8/10/2019 ACP MCQ.docx
28/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
c) func(*array);
d) func(array[size]);
Answer:a & b
1. Which of the following can never be sent by call-by-value?
a) Variableb) Arrayc) Structures
d) Both (b) and (c)
Answer:b
2. Which type of variables can have same name in different function:
a) global variablesb) static variables
c) Function arguments
d) Both (b) and (c)
Answer:d
3. Arguments that take input by user before running a program are called?a) main function arguments
b) main arguments
c) Command-Line arguments
d) Parameterized argumentsAnswer:c
4. The maximum number of arguments that can be passed in a single function are_____________a) 127
b) 253c) 361d) No limits in number of arguments
Answer:b
5. What is the output of this C code?
1. #include
2. void m(int *p, int *q)
3. {
4. int temp = *p; *p = *q; *q = temp;
5.
}6. void main()
7. {
8. int a = 6, b = 5;9. m(&a, &b);
10. printf("%d %d\n", a, b);
11. }
-
8/10/2019 ACP MCQ.docx
29/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
a) 5 6
b) 6 5
c) 5 5
d) 6 6Answer:a
6. What is the output of this C code?
1. #include 2. void m(int *p)
3. {
4. int i = 0;
5. for(i = 0;i < 5; i++)6. printf("%d\t", p[i]);
7. }
8. void main()
9.
{10. int a[5] = {6, 5, 3};
11. m(&a);
12. }
a) 0 0 0 0 0b) 6 5 3 0 0c) Run time error
d) 6 5 3 junk junk
Answer:b
7. What is the output of this C code?
1. #include
2. void m(int p, int q)3. {
4. int temp = p;
5. p = q;
6. q = temp;7. }
8. void main()
9. {
10.
int a = 6, b = 5;11. m(a, b);
12. printf("%d %d\n", a, b);
13. }
a) 5 6b) 5 5c) 6 5
-
8/10/2019 ACP MCQ.docx
30/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
d) 6 6
Answer:c
8. What is the output of this C code?
1.
#include 2. void m(int p, int q)
3. {
4. printf("%d %d\n", p, q);5. }
6. void main()
7. {
8. int a = 6, b = 5;9. m(a);
10. }
a) 6b) 6 5
c) 6 junk valued) Compile time error
Answer:d
9. What is the output of this C code?
1. #include
2. void m(int p)
3. {
4.
printf("%d\n", p);5. }
6. void main()
7. {8. int a = 6, b = 5;
9. m(a, b);
10. printf("%d %d\n", a, b);
11. }
a) 6b) 6 5
c) 6 junk valued) Compile time error
Answer:d
1. What is the output of this C code?
1. #include
2. void main()
3. {
-
8/10/2019 ACP MCQ.docx
31/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
4. int a[3] = {1, 2, 3};
5. int *p = a;
6. printf("%p\t%p", p, a);
7. }
a) Same address is printed.b) Different address is printed.c) Compile time error
d) Nothing
Answer:a
2. What is the output of this C code?
1. #include
2. void main()
3. {
4.
char *s = "hello";5. char *p = s;
6. printf("%p\t%p", p, s);7. }
a) Different address is printedb) Same address is printed
c) Run time error
d) Nothing
Answer:b
3. What is the output of this C code?
1. #include
2. void main()3. {
4. char *s= "hello";
5. char *p = s;6. printf("%c\t%c", p[0], s[1]);
7. }
a) Run time error
b) h hc) h e
d) h lAnswer:c
4. What is the output of this C code?
1. #include 2. void main()
-
8/10/2019 ACP MCQ.docx
32/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
3. {
4. char *s= "hello";
5. char *p = s;
6. printf("%c\t%c", *(p + 3), s[1]);7. }
a) h eb) l l
c) l o
d) l eAnswer:d
5. What is the output of this C code?
1. #include
2. void main()
3.
{4. char *s= "hello";
5. char *p = s;6. printf("%c\t%c", 1[p], s[1]);
7. }
a) h h
b) Run time error
c) l l
d) e eAnswer:d
6. What is the output of the code given below?
1. #include 2. void foo( int[] );
3. int main()
4. {5. int ary[4] = {1, 2, 3, 4};
6. foo(ary);
7. printf("%d ", ary[0]);
8. }
9.
void foo(int p[4])10. {
11. int i = 10;
12. p = &i;13. printf("%d ", p[0]);
14. }
a) 10 10
b) Compile time error
-
8/10/2019 ACP MCQ.docx
33/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
c) 10 1
d) Undefined behaviour
Answer:c
7. What is the output of the code given below?
1. #include
2. int main()
3. {4. int ary[4] = {1, 2, 3, 4};
5. int *p = ary + 3;
6. printf("%d\n", p[-2]);
7. }
a) 1b) 2
c) Compile time errord) Some garbage value
Answer:b
8. What is the output of the code given below?
1. #include
2. int main()3. {
4. int ary[4] = {1, 2, 3, 4};
5. int *p = ary + 3;
6.
printf("%d %d\n", p[-2], ary[*p]);7. }
a) 2 3b) Compile time error
c) 2 4
d) 2 somegarbagevalueAnswer:d
1. What is the output of this C code?
1.
#include 2. int main()3. {
4. int ary[4] = {1, 2, 3, 4};
5. printf("%d\n", *ary);6. }
a) 1b) Compile time error
-
8/10/2019 ACP MCQ.docx
34/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
c) Some garbage value
d) Undefined variable
Answer:a
2. What is the output of this C code?
1. #include
2. int main()
3. {4. const int ary[4] = {1, 2, 3, 4};
5. int *p;
6. p = ary + 3;
7. *p = 5;8. printf("%d\n", ary[3]);
9. }
a) 4b) 5
c) Compile time errord) 3
Answer:b
3. Different ways to initialize an array with all elements as zero are
a) int array[5] = {};
b) int array[5] = {0};
c) int a = 0, b = 0, c = 0;int array[5] = {a, b, c};
d) All of the mentionedAnswer:d
4. The elements in the array of the following code areint array[5] = {5};
a) 5, 5, 5, 5, 5
b) 5, 0, 0, 0, 0
c) 5, (garbage), (garbage), (garbage), (garbage)d) (garbage), (garbage), (garbage), (garbage), 5
Answer:b
5. Which of the following declaration is illegal?a) int a = 0, b = 1, c = 2;
int array[3] = {a, b, c};
b) int size = 3;int array[size];
c) int size = 3;
int array[size] = {1, 2, 3};d) All of the mentioned
Answer:c
-
8/10/2019 ACP MCQ.docx
35/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
6. An array of similar data types which themselves are collection of dissimilar data type are
a) Linked Lists
b) Trees
c) Array of Structured) All of the mentioned
Answer:c
7. Comment on an array of void data type:
a) It can store any data-type
b) It only stores element of similar data type to first elementc) It acquires the data type with the highest precision in it
d) You cannot have an array of void data type
Answer:d
8. What is the output of the code given below?
1.
#include 2. int main()
3. {4. int ary[4] = {1, 2, 3, 4};
5. int p[4];
6. p = ary;
7. printf("%d\n", p[1]);8. }
a) 1b) Compile time error
c) Undefined behaviourd) 2Answer:b
1. What is the output of this C code?
1. #include 2. int main()
3. {
4. double *ptr = (double *)100;
5. ptr = ptr + 2;
6.
printf("%u", ptr);7. }
a) 102
b) 104
c) 108d) 116
Answer:d
-
8/10/2019 ACP MCQ.docx
36/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
2. Comment on the output of this C code?
1. #include 2. int main()
3. {
4.
int *p = (int *)2;5. int *q = (int *)3;6. printf("%d", p + q);
7. }
a) 2
b) 3
c) 5d) Compile time error
Answer:d
3. Which of the following operand can be applied to pointers p and q?(Assuming initialization as int *a = (int *)2; int *b = (int *)3;)
a) a + bb) ab
c) a * b
d) a / b
Answer:b
4. What is the size of *ptr in a 32-bit machine, (assuming initialization as int *ptr = 10;)?
a) 1b) 2
c) 4d) 8Answer:c
5. Which of following logical operation can be applied to pointers?
(Assuming initialization int *a = 2; int *b = 3;)
a) a | b
b) a ^ bc) a & b
d) None of the mentioned
Answer:d
6. What is the output of this C code?
1. #include
2. void main()
3. {4. char *s = "hello";
5. char *p = s;
6. printf("%c\t%c", *(p + 1), s[1]);
-
8/10/2019 ACP MCQ.docx
37/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
7. }
a) h eb) e l
c) h h
d) e eAnswer:d
7. What is the output of this C code?
1. #include
2. void main()3. {4. char *s = "hello";
5. char *p = s;
6. printf("%c\t%c", *p, s[1]);
7.
}
a) e hb) Compile time error
c) h h
d) h eAnswer:d
8. What is the output of this C code?
1. #include
2.
void main()3. {
4. char *s = "hello";
5. char *n = "cjn";6. char *p = s + n;
7. printf("%c\t%c", *p, s[1]);
8. }
a) h e
b) Compile time error
c) c o
d) h nAnswer:b
1. What is the output of this C code?
1. #include
2. void main()
3. {4. char *s = "hello";
-
8/10/2019 ACP MCQ.docx
38/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
5. char *p = s * 3;
6. printf("%c\t%c", *p, s[1]);
7. }
a) h e
b) l ec) Compile time errord) l h
Answer:c
2. What is the output of this C code?
1. #include 2. void main()
3. {
4. char *s= "hello";
5.
char *p = s + 2;6. printf("%c\t%c", *p, s[1]);
7. }
a) l e
b) h ec) l l
d) h l
Answer:a
3. What is the output of this C code?
1. #include
2. int main()
3. {4. void *p;
5. int a[4] = {1, 2, 3, 8};
6. p = &a[3];7. int *ptr = &a[2];
8. int n = p - ptr;
9. printf("%d\n", n);
10. }
a) 1
b) Compile time errorc) Segmentation fault
d) 4
Answer:b
4. What is the output of this C code?
-
8/10/2019 ACP MCQ.docx
39/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
LEARNS FROM THE MASTERS
1. #include
2. int main()
3. {
4. void *p;5. int a[4] = {1, 2, 3, 4};
6.
p = &a[3];7. int *ptr = &a[2];8. int n = (int*)p - ptr;
9. printf("%d\n", n);10. }
a) 1
b) Compile time error
c) Segmentation faultd) 4
Answer:a
5. What is the output of this C code?
1. #include
2. int main()
3. {
4. int a[4] = {1, 2, 3, 4};5. int b[4] = {1, 2, 3, 4};
6. int n = &b[3] - &a[2];
7. printf("%d\n", n);8. }
a) -3b) 5
c) 4
d) Compile time errorAnswer:a
6. What is the output of this C code?
1. #include
2. int main()
3.
{4. int a[4] = {1, 2, 3, 4};
5. int *p = &a[1];
6. int *ptr = &a[2];7. ptr = ptr * 1;
8. printf("%d\n", *ptr);
9. }
-
8/10/2019 ACP MCQ.docx
40/40
REAL DIPLOMA & ENGINEERING CLASSES
ADVANCE PROGRAMMING IN C RAJNISH SRIVASTAV-9601253885
a) 2
b) 1
c) Compile time error
d) Undefined behaviourAnswer:c
7. What is the output of this C code?
1. #include 2. int main()
3. {
4. int a[4] = {1, 2, 3, 4};
5. int *ptr = &a[2];6. float n = 1;
7. ptr = ptr + n;
8. printf("%d\n", *ptr);
9.
}
a) 4b) 3
c) Compile time error
d) Undefined behaviour
Answer:c
8. What is the output of this C code?
1. #include
2.
int main()3. {
4. int a[4] = {1, 2, 3, 4};
5. void *p = &a[1];6. void *ptr = &a[2];
7. int n = 1;
8. n = ptr - p;
9. printf("%d\n", n);10. }
a) 1
b) 4c) Compile time error
d) Depends on the compiler
Answer:b