Question:
Predict the output of the following program:

#include <stdio.h>
int main()
{
    int check = 20, arr[] = {10, 20, 30};
    switch (check)
    {
        case arr[0]: printf(\"Geeks \");
        case arr[1]: printf(\"Quiz \");
        case arr[2]: printf(\"GeeksQuiz\");
    }
    return 0;
}

``````C

Choices:
- Quiz
- Quiz GeeksQuiz
- GeeksQuiz
- Compile-time error


Question:
What is the output of the following program?

#include <stdio.h>
int main()
{
    char check = \'a\';
    switch (check)
    {
        case \'a\' || 1: printf(\"Geeks \");

        case \'b\' || 2: printf(\"Quiz \");
                    break;
        default: printf(\"GeeksQuiz\");
    }
    return 0;
}

``````C

Choices:
- Geeks
- Geeks Quiz
- Geeks Quiz GeeksQuiz
- Compile-time error


Question:
What’s going to happen when we compile and run the following C program snippet?

#include \"stdio.h\"
int main()
{
 int a = 10;
 int b = 15;

 printf(\"=%d\",(a+1),(b=a+2));
 printf(\" %d=\",b);

 return 0;
}

``````C

Choices:
- =11 15=
- =11 12=
- Compiler Error due to (b=a+2) in the first printf().
- No compile error but output would be =11 X= where X would depend on compiler implementation.


Question:
What is output of following C - Code?

#include <stdio.h>
#include <stdarg.h>
int fun(int n, ...)
{
    int i, j = 1, val = 0;
    va_list p;
    va_start(p, n);
    for (; j < n; ++j)
    {
        i = va_arg(p, int);
        val += i;
    }
    va_end(p);
    return val;
}
int main()
{
    printf(\"%d\\n\", fun(4, 1, 2, 3));
    return 0;
}

``````C

Choices:
- 3
- 5
- 6
- 10


Question:
Pick the best statement for the below program:

#include \"stdio.h\"

int main()
{
 struct {int a[2];} arr[] = {{1},{2}};

 printf(\"%d %d %d %d\",arr[0].a[0],arr[0].a[1],arr[1].a[0],arr[1].a[1]);

 return 0;
}

``````C

Choices:
- Compile error because arr has been defined using struct type incorrectly. First struct type should be defined using tag and then arr should be defined using that tag.
- Compile error because apart from definition of arr, another issue is in the initialization of array of struct i.e. arr[].
- Compile error because of initialization of array of struct i.e. arr[].
- No compile error and it’ll print 1 2 0 0
- No compile error and it’ll print 1 0 2 0


Question:
Consider the following code.  The function myStrcat concatenates two strings.  It appends all characters of b to end of a.  So the expected output is "Geeks Quiz".  The program compiles fine but produces segmentation fault when run.

void myStrcat(char *a, char *b)
{
    int m = strlen(a);
    int n = strlen(b);
    int i;
    for (i = 0; i <= n; i++)
       a[m+i]  = b[i];
}

int main()
{
    char *str1 = \"Geeks \";
    char *str2 = \"Quiz\";
    myStrcat(str1, str2);
    printf(\"%s \", str1);
    return 0;
}

``````C

Which of the following changes can correct the program so that it prints "Geeks Quiz"?

Choices:
- char *str1 = "Geeks ";  can be  changed to char str1[100] = "Geeks ";
- char *str1 = "Geeks "; can be changed to char str1[100] = "Geeks "; and  a line a[m+n-1] = \'\\0\' is added at the end of myStrcat
- A line a[m+n-1] = \'\\0\' is added at the end of myStrcat
- A line \'a = (char *)malloc(sizeof(char)*(strlen(a) + strlen(b) + 1)) is added at the beginning of myStrcat()


Question:
Predict the output of the below program:

#include <stdio.h>
int main()
{
    int i = 3;
    switch(i)
    {
        printf(\"Outside \");
        case 1: printf(\"Geeks\");
            break;
        case 2: printf(\"Quiz\");
            break;
        defau1t: printf(\"GeeksQuiz\");
    }
    return 0;
}

``````C

Choices:
- Outside GeeksQuiz
- GeeksQuiz
- Nothing gets printed


Question:
What will be the output of the following C program segment? (GATE CS 2012)

char inchar = \'A\';
switch (inchar)
{
case \'A\' :
    printf (\"choice A \\n\") ;
case \'B\' :
    printf (\"choice B \") ;
case \'C\' :
case \'D\' :
case \'E\' :
default:
    printf (\"No Choice\") ;
}

``````C

Choices:
- No choice
- Choice A
-
Choice A
Choice B No choice
- Program gives no output as it is erroneous


Question:
#include <stdio.h>
int main()
{
  int i;
  for (i = 1; i != 10; i += 2)
    printf(\" GeeksQuiz \");
  return 0;
}

``````C

Choices:
- GeeksQuiz GeeksQuiz GeeksQuiz GeeksQuiz GeeksQuiz
- GeeksQuiz GeeksQuiz GeeksQuiz .... infinite times
- GeeksQuiz GeeksQuiz GeeksQuiz GeeksQuiz
- GeeksQuiz GeeksQuiz GeeksQuiz GeeksQuiz  GeeksQuiz GeeksQuiz


Question:
Output of following C program?

#include<stdio.h>
int main()
{
    int i = 0;
    for (printf(\"1st\\n\"); i < 2 && printf(\"2nd\\n\"); ++i && printf(\"3rd\\n\"))
    {
        printf(\"*\\n\");
    }
    return 0;
}

``````C

Choices:
-
1st
2nd
*
3rd
2nd
*
-
1st
2nd
*
3rd
2nd
*
3rd
-
1st
2nd
3rd
*
2nd
3rd
-
1st
2nd
3rd
*
1st
2nd
3rd


Question:
Predict the output of following program?

#include <stdio.h>

int main() {
    int x = 10;
    int y = 20;
    x += (y += 10);
    printf("%d %d", x, y);
    return 0;
}

``````C

Choices:
- 40 20
- 40 30
- 30 30
- 30 40


Question:
#include<stdio.h>
int main()
{
  int a = 2,b = 5;
  a = a^b;
  b = b^a;
  printf(\"%d %d\",a,b);
  return 0;
}

``````C

Choices:
- 5 2
- 2 5
- 7 7
- 7 2


Question:
In the following program, X represents the Data Type of the variable check.

#include <stdio.h>
int main()
{
    X check;
    switch (check)
    {
        // Some case labels
    }
    return 0;
}

``````C

Which of the following cannot represent X?

Choices:
- int
- char
- enum
- float


Question:
Consider the following C code. Assume that unsigned long int
``````C
 type length is 64 bits.

unsigned long int fun(unsigned long int n) {
        unsigned long int i, j = 0, sum = 0;
        for( i = n; i > 1; i = i/2) j++;
        for( ; j > 1; j = j/2) sum++;
        return sum;
}

``````C

The value returned when we call fun
``````C
 with the input 240 is

Choices:
- 4
- 5
- 6
- 40


Question:
#include<stdio.h>
int main()
{
  char *s[] = { \"knowledge\",\"is\",\"power\"};
  char **p;
  p = s;
  printf(\"%s \", ++*p);
  printf(\"%s \", *p++);
  printf(\"%s \", ++*p);

  return 0;
}

``````C

Choices:
- is power
- nowledge nowledge s
- is ower
- nowledge knowledge is


Question:
#include <stdio.h>
int main()
{
  int a = 10, b = 20, c = 30;
  if (c > b > a)
    printf(\"TRUE\");
  else
    printf(\"FALSE\");
  return 0;
}

``````C

Choices:
- TRUE
- FALSE
- Compiler Error
- Output is compiler dependent


Question:
#include<stdio.h>
int main()
{
   int n;
   for (n = 9; n!=0; n--)
     printf(\"n = %d\", n--);
   return 0;
}

``````C

What is the output?

Choices:
- 9 7 5 3 1
- 9 8 7 6 5 4 3 2 1
- Infinite Loop
- 9 7 5 3


Question:
Output?

#include <stdio.h>
int main()
{
    int c = 5, no = 10;
    do {
        no /= c;
    } while(c--);

    printf (\"%d\\n\", no);
    return 0;
}

``````C

Choices:
- 1
- Runtime Error
- 0
- Compiler Error


Question:
# include <stdio.h>
int main()
{
   int i = 0;
   for (i=0; i<20; i++)
   {
     switch(i)
     {
       case 0:
         i += 5;
       case 1:
         i += 2;
       case 5:
         i += 5;
       default:
         i += 4;
         break;
     }
     printf(\"%d  \", i);
   }
   return 0;
}

``````C

Choices:
- 5  10  15  20
- 7  12  17  22
- 16 21
- Compiler Error


Question:
#include <stdio.h>
#define get(s) #s

int main()
{
    char str[] = get(GeeksQuiz);
    printf(\"%s\", str);
    return 0;
}

``````C

Choices:
- Compiler Error
- #GeeksQuiz
- GeeksQuiz
- GGeeksQuiz


Question:
What is the output for the following code snippet?

#include<stdio.h>
#define A -B
#define B -C
#define C 5

int main()
{
  printf(\"The value of A is %d\\n\", A);
  return 0;
}

``````CPP

This question is contributed by Aastha Anand.

Choices:
- The value of A is 4
- The value of A is 5
- Compilation Error
- Runtime Error


Question:
Suppose someone writes increment macro (i.e. which increments the value by one) in following ways:

#define INC1(a) ((a)+1)

#define INC2 (a) ((a)+1)

#define INC3( a ) (( a ) + 1)

#define INC4 ( a ) (( a ) + 1)

``````C

Pick the correct statement for the above macros.

Choices:
- Only INC1 is correct.
- All (i.e. INC1, INC2, INC3 and INC4) are correct.
- Only INC1 and INC3 are correct.
- Only INC1 and INC2 are correct.


Question:
Predict the output of the below program:

#include <stdio.h>

int main()
{
    printf(\"%c \", 5[\"GeeksQuiz\"]);
    return 0;
}

``````C

Choices:
- Compile-time error
- Runtime error
- Q
- s


Question:
Predict the output of below program:

#include <stdio.h>
int main()
{
    printf(\"%c \", \"GeeksQuiz\"[5]);
    return 0;
}

``````C

Choices:
- Compile-time error
- Runtime error
- Q
- s


Question: Which of the following is true

Choices:
- gets() can read a string with newline characters but a normal scanf() with %s can not.
- gets() can read a string with spaces but a normal scanf() with %s can not.
- gets() can always replace scanf() without any additional code.
- None of the above


Question:
#include<stdio.h>

int main()
{
    char *s = \"Geeks Quiz\";
    int n = 7;
    printf(\"%.*s\", n, s);
    return 0;
}

``````C

Choices:
- Geeks Quiz
- Nothing is printed
- Geeks Q
- Geeks Qu


Question:
Predict the output of following program?

#include <stdio.h>
int main(void)
{
   int x = printf(\"GeeksQuiz\");
   printf(\"%d\", x);
   return 0;
}

``````C

Choices:
- GeeksQuiz9
- GeeksQuiz10
- GeeksQuizGeeksQuiz
- GeeksQuiz1


Question:
The following program won’t compile because there’re space between macro name and open parenthesis.

#include \"stdio.h\"

#define MYINC   (  a  )  (  ( a )  +  1 )

int main()
{

 printf(\"GeeksQuiz!\");

 return 0;
}

``````C

Choices:
- TRUE
- FALSE


Question:
Consider the following statements
#define hypotenuse (a, b) sqrt (a*a+b*b);

The macro call hypotenuse(a+2,b+3);

Choices:
- Finds the hypotenuse of a triangle with sides a+2 and b+3
- Finds the square root of (a+2)2 and (b+3)2
- Is invalid
- Find the square root of 3*a + 4*b + 5


Question:
What is the output of the following C program?

#include<stdio.h>
#define SQR(x) (x*x)
int main()
{
    int a;
    int b=4;
    a=SQR(b+2);
    printf(\"%d\\n\",a);
    return 0;
}

``````C

Choices:
- 14
- 36
- 18
- 20


Question: The translator which performs macro calls expansion is called:

Choices:
- Macro processor
- Micro pre - processor
- Macro pre - processor
- Dynamic Linker


Question: What is the use of "#pragma once"?

Choices:
- Used in a header file to avoid its inclusion more than once.
- Used to avoid multiple declarations of same variable.
- Used in a c file to include a header file at least once.
- Used to avoid assertions


Question: Which file is generated after pre-processing of a C program?

Choices:
- .p
- .i
- .o
- .m


Question:
What is the output of following program?

#include <stdio.h>

int main()
{
   int a = 1;
   int b = 1;
   int c = a || --b;
   int d = a-- && --b;
   printf(\"a = %d, b = %d, c = %d, d = %d\", a, b, c, d);
   return 0;
}

``````C

Choices:
- a = 0, b = 1, c = 1, d = 0
- a = 0, b = 0, c = 1, d = 0
- a = 1, b = 1, c = 1, d = 1
- a = 0, b = 0, c = 0, d = 0


Question:
Output of following program?

#include <stdio.h>
int f1() { printf (\"Geeks\"); return 1;}
int f2() { printf (\"Quiz\"); return 1;}

int main()
{
  int p = f1() + f2();
  return 0;
}

``````C

Choices:
- GeeksQuiz
- QuizGeeks
- Compiler Dependent
- Compiler Error


Question:
#include <stdio.h>
int main()
{
    //Assume sizeof character is 1 byte and sizeof integer is 4 bytes
    printf(\"%d\", sizeof(printf(\"GeeksQuiz\")));
    return 0;
}

``````C

Choices:
- GeeksQuiz4
- 4GeeksQuiz
- GeeksQuiz9
- 4
- Compile-time error


Question:
#include <stdio.h>
int main()
{
    int i = 5, j = 10, k = 15;
    printf(\"%d \", sizeof(k /= i + j));
    printf(\"%d\", k);
    return 0;
}

``````C

Assume size of an integer as 4 bytes. What is the output of above program?

Choices:
- 4 1
- 4 15
- 2 1
- Compile-time error


Question:
What is the output of below program?

#include <stdio.h>
int foo(int* a, int* b)
{
    int sum = *a + *b;
    *b = *a;
    return *a = sum - *b;
}
int main()
{
    int i = 0, j = 1, k = 2, l;
    l = i++ || foo(&j, &k);
    printf(\"%d %d %d %d\", i, j, k, l);
    return 0;
}

``````C

Choices:
- 1 2 1 1
- 1 1 2 1
- 1 2 2 1
- 1 2 2 2


Question:
#include <stdio.h>

int main()
{
    int i;

    i = 1, 2, 3;
    printf("%d", i);

    return 0;
}

Choices:
- 1
- 3
- Garbage value
- Compile time error


Question:
How many lines of output does the following C code produce?

#include<stdio.h>
float i=2.0;
float j=1.0;
float sum = 0.0;
main()
{
    while (i/j > 0.001)
    {
        j+=j;
        sum=sum+(i/j);
        printf(\"%f\\n\", sum);
    }
}

``````C

Choices:
- 8
- 9
- 10
- 11


Question:
#include <stdio.h>

int main()
{
    int i = (1, 2, 3);

    printf("%d", i);

    return 0;
}

Choices:
- 1
- 3
- Garbage value
- Compile time error


Question:
Typically, library header files in C (e.g. stdio.h) contain not only declaration of functions and macro definitions but they contain definition of user defined data types (e.g. struct, union etc), typedefs and definition of global variables as well. So if we include the same header file more than once in a C program, it would result in compile issue because re-definition of many of the constructs of the header file would happen. So it means the following program will give compile error.

#include “stdio.h”
#include “stdio.h”
#include “stdio.h”

int main()
{
 printf(“Whether this statement would be printed?”)
 return 0;
}

``````C

Choices:
- TRUE
- FALSE


Question: Which of the following functions from “stdio.h” can be used in place of printf()?

Choices:
- fputs() with FILE stream as stdout.
- fprintf() with FILE stream as stdout.
- fwrite() with FILE stream as stdout.
- All of the above three - a, b and c.
- In “stdio.h”, there’s no other equivalent function of printf().


Question:
Consider the following C - code :

#include \"stdio.h\"

int foo(int a)
{
 printf(\"%d\",a);
 return 0;
}

int main()
{
 foo;
 return 0;
}

``````C

Which of the following option is correct?

Choices:
- It’ll result in compile error because foo is used without parentheses.
- No compile error and some garbage value would be passed to foo function. This would make foo to be executed with output “garbage integer”.
- No compile error but foo function wouldn’t be executed. The program wouldn\'t print anything.
- No compile error and ZERO (i.e. 0) would be passed to foo function. This would make foo to be executed with output 0.


Question: Normally user programs are prevented from handling I/O directly by I/O instructions in them. For CPUs having explicit I/O instructions, such I/O protection is ensured by having the I/O instructions privileged. In a CPU with memory mapped I/O, there is no explicit I/O instruction. Which one of the following is true for a CPU with memory mapped I/O?

Choices:
- I/O protection is ensured by operating system routine (s)
- I/O protection is ensured by a hardware trap
- I/O protection is ensured during system configuration
- I/O protection is not possible


Question: What is the return type of getchar()?

Choices:
- int
- char
- unsigned char
- float


Question:
Output of following program?

#include<stdio.h>
int main()
{
    printf(\"%d\", printf(\"%d\", 1234));
    return 0;
}

``````C

Choices:
- 12344
- 12341
- 11234
- 41234


Question:
#include <stdio.h>

int main()
{
    int i = 1, 2, 3;

    printf("%d", i);

    return 0;
}

Choices:
- 1
- 3
- Garbage value
- Compile time error


Question:
Consider the following C program:

#include <stdio.h>
void fun1(char *s1, char *s2) {
  char *temp;
  temp = s1;
  s1 = s2;
  s2 = temp;
}
void fun2(char **s1, char **s2) {
  char *temp;
  temp = *s1;
  *s1 = *s2;
  *s2 = temp;
}
int main() {
  char *str1 = \"Hi\", *str2 = \"Bye\";
  fun1(str1, str2);
  printf(\"%s %s\", str1, str2);
  fun2(&str1, &str2);
  printf(\"%s %s\", str1, str2);
  return 0;
}

``````C

The output of the program above is

Choices:
- Hi Bye Bye Hi
- Hi Bye Hi Bye
- Bye Hi Hi Bye
- Bye Hi Bye Hi


Question:
#include <stdio.h>
int main()
{
    int x = 3;
    if (x == 2); x = 0;
    if (x == 3) x++;
    else x += 2;

    printf(\"x = %d\", x);

    return 0;
}

``````C

Choices:
- x = 4
- x = 2
- Compiler Error
- x = 0


Question:
What is the value returned by the function f given below when n = 100?
int f (int n)
{ if (n = = 0) then return n;
else
return n + f(n-2);
}

Choices:
- 2550
- 2556
- 5220
- 5520


Question:
Write the output of the following C program

#include <stdio.h>

  int main (void)
  {
  int shifty;
  shifty = 0570;
  shifty = shifty >>4;
  shifty = shifty <<6;
  printf(\"the value of shifty is %o\",shifty);
  }

``````C

Choices:
- the value of shifty is 15c0
- the value of shifty is 4300
- the value of shifty is 5700
- the value of shifty is 2700


Question:
The following three \'C\' language statements is equivalent to which single statement?
y=y+1;
z=x+y;
x=x+1

Choices:
- z = x + y + 2;
- z = (x++) + (++y);
- z = (x++) + (y++);
- z = (x++) + (++y) + 1;


Question:
Given i = 0, j = 1, k = –1
x = 0.5, y = 0.0
What is the output of the following expression in C language ?
x * y < i + j || k

Choices:
- -1
- 0
- 1
- 2


Question: Loop unrolling is a code optimization technique:

Choices:
- that avoids tests at every iteration of the loop.
- that improves performance by decreasing the number of instructions in a basic block.
- that exchanges inner loops with outer loops
- that reorders operations to allow multiple computations to happen in parallel


Question:
Output of following C++ code will be?

#include <iostream>
using namespace std;

class X
{
public:
    int x;
};

int main()
{
    X a = {10};
    X b = a;
    cout << a.x << " " << b.x;
    return 0;
}

``````C++

Choices:
- Compiler Error
- 10 followed by Garbage Value
- 10 10
- 10 0


Question:
What would happen when we compile and run this program?

#include < stdio.h >

int main()

{

  int i;

  goto LOOP;

  for (i = 0 ; i < 10 ; i++)

  {

     printf(\"GeeksQuiz \n\");

     LOOP:

      break;

  }

  return 0;

}

``````C

Choices:
- No compile error and it will print GeeksQuiz 10 times because goto label LOOP wouldn’t come in effect.
- No compile error and it’ll print GeeksQuiz only once because goto label LOOP would come in picture only after entering for loop.
- Compile Error because any goto label isn’t allowed in for loop in C.
- No compile error but behaviour of the program would depend on C compiler due to nondeterministic behaviour of goto statement.
- No compile error and it will not print anything.


Question:
A typical “switch” body looks as follows:

switch (controlling_expression)

{

  case label1:

    /*label1 statements*/

    break;

  case label2:

    /*label1 statements*/

    break;

  default:

    /*Default statements*/

}

``````C

Which of the following statement is not correct statement?

Choices:
- “switch” body may not have any “case” label at all and it would still compile.
- “switch” body may not have the “default” label and it would still compile.
- “switch” body may contain more than one “case” labels where the label value of these “case” is same and it would still compile. If “switch” controlling expression results in this “case” label value, the “case” which is placed first would be executed.
- “switch” body may not have any “break” statement and it would still compile.
- “switch” body can have the “default” label at first i.e. before all the other “case” labels. It would still compile.


Question: Which of the following is correct with respect to “Jump Statements” in C?

Choices:
- goto
- continue
- break
- return
- All of the above.


Question:
Consider the following program fragment
if(a > b)
if(b > c)
s1;
else s2;

s2 will be executed if

Choices:
- a <= b
- b > c
- b >= c and a <= b
- a > b and b <= c


Question:
Output of following program?

#include <iostream>
using namespace std;

class Point {
    Point() { cout << "Constructor called"; }
};

int main()
{
    Point t1;
    return 0;
}

``````C++

Choices:
- Runtime Error
- None of these
- Constructor called
- Compiler Error


Question: Given that x = 7.5, j = -1.0, n = 1.0, m = 2.0 the value of - - x + j == x>n> = m is:

Choices:
- 0
- 1
- 2
- 3


Question: If n has 3, then the statement a[++n]=n++;

Choices:
- assigns 3 to a[5]
- assigns 4 to a[5]
- assigns 4 to a[4]
- what is assigned is compiler dependent


Question:
#include "stdio.h"

int main()

{

  int x, y = 5, z = 5;

  x = y == z;

  printf("%d", x);

  getchar();

  return 0;

}

Choices:
- 0
- 1
- 5
- Compiler Error


Question:
#include <stdio.h>
int main()
{
    int i = 3;
    printf(\"%d\", (++i)++);
    return 0;
}

``````C

What is the output of the above program?

Choices:
- 3
- 4
- 5
- Compile-time error


Question:
Consider the following program fragment

i=6720; j=4;
while (i%j)==0
{
i=i/j;
j=j+1;
}

On termination j will have the value

Choices:
- 4
- 8
- 9
- 6720


Question:
The output of the following program is

main()
{
static int x[] = {1,2,3,4,5,6,7,8}
int i;
for (i=2; i<6; ++i)
x[x[i]]=x[i];
for (i=0; i<8; ++i)
printf("%d", x[i]);
}

Choices:
- 1 2 3 3 5 5 7 8
- 1 2 3 4 5 6 7 8
- 8 7 6 5 4 3 2 1
- 1 2 3 5 4 6 7 8


Question:
The for loop
for (i=0; i<10; ++i)
printf("%d", i&1);

prints:

Choices:
- 0101010101
- 0111111111
- 0000000000
- 1111111111


Question:
Consider the following C function

void swap (int a, int b)
{
   int temp;
   temp = a;
   a = b;
   b = temp;
}

``````C

In order to exchange the values of two variables x and y.

Choices:
- Call swap (x, y)
- Call swap (&x, &y)
- swap(x,y) cannot be used as it does not return any value
- swap(x,y) cannot be used as the parameters are passed by value


Question: In _______, the bodies of the two loops are merged together to form a single loop provided that they do not make any references to each other.

Choices:
- Loop unrolling
- Strength reduction
- Loop concatenation
- Loop jamming


Question:
Consider the following pseudocode:  x:=1;
i:=1;
while (x ? 500)
begin
x:=2x ;
i:=i+1;
end
What is the value of i at the end of the pseudocode?

Choices:
- 4
- 5
- 6
- 7


Question: Which of the following is not a logical operator?


Question: 'C' Language can be used in ??

Choices:
- Both System Software and Embedded Systems
- Only System Software
- Only Embedded Systems
- None


Question: When a copy constructor may be called?

Choices:
- When an object of the class is returned by value.
- When an object of the class is passed (to a function) by value as an argument.
- When an object is constructed based on another object of the same class
- When compiler generates a temporary object.
- All of the above


Question: In the context of "break" and "continue" statements in C, pick the best statement.

Choices:
- “break” can be used in “for”, “while” and “do-while” loop body.
- “continue” can be used in “for”, “while” and “do-while” loop body.
- “break” and “continue” can be used in “for”, “while”, “do-while” loop body and “switch” body.
- “break” and “continue” can be used in “for”, “while” and “do-while” loop body. But only “break” can be used in “switch” body.
- “break” and “continue” can be used in “for”, “while” and “do-while” loop body. Besides, “continue” and “break” can be used in “switch” and “if-else” body.


Question:
Predict the output?

int fun(char *str1){  char *str2 = str1;  while(*++str1);  return (str1-str2);}int main(){  char *str = \"GeeksQuiz\";  printf(\"%d\", fun(str));  return 0;}

``````C

Choices:
- 10
- 9
- 8
- Random Number


Question: Consider the following ANSI C code segment: z=x + 3 + y->f1 + y->f2; for (i = 0; i < 200; i = i + 2) { if (z > i) { p = p + x + 3; q = q + y->f1; } else { p = p + y->f2; q = q + x + 3; } } Assume that the variable y points to a struct (allocated on the heap) containing two fields f1 and f2, and the local variables x, y, z, p, q, and i are allotted registers. Common sub-expression elimination (CSE) optimization is applied on the code. The number of addition and the dereference operations (of the form y ->f1 or y ->f2) in the optimized code, respectively, are:

Choices:
- 403 and 102
- 203 and 2
- 303 and 102
- 303 and 2


Question:
What does the following C statement mean?

 scanf(\"%4s\", str);

``````C

Choices:
- Read exactly 4 characters from console.
- Read maximum 4 characters from console.
- Read a string str in multiples of 4
- Nothing


Question:
#include <stdio.h>
// Assume base address of \"GeeksQuiz\" to be 1000
int main()
{
   printf(5 + \"GeeksQuiz\");
   return 0;
}

``````C

Choices:
- GeeksQuiz
- Quiz
- 1005
- Compile-time error


Question:
Consider the following C code segment:

#include
main()
{
    int i, j , x ;
    scanf("%d", &x);
    i = 1 ; j = 1;
    while ( i< 10 ) {
          j = j * i;
          i = i + 1;
          if (i == x) break ;
          }
 }

For the program fragment above, which of the following statements about the variables i and j must be true after execution of this program? [!(exclamation) sign denotes factorial in the answer]

Choices:
- ( j = (x - 1 )! ) ? (i >=  x)
- ( j = 9!) ? (i =10)
- (( j  =  10!) ? (i = 10 )) V (( j = (x - 1)!) ? (i = x ))
- (( j = 9!) ? (i = 10)) V (( j = (x - 1)!) ? (i = x ))


Question:
What is the output of the following C code?

#include
int main()
{
int index;
for(index=1; index<=5; index++)
{
printf("%d", index);
if (index==3)
continue;
}
}

Choices:
- 1245
- 12345
- 12245
- 12354


Question: In C++, which system - provided function is called when no handler is provided to deal with an exception?

Choices:
- terminate ( )
- unexpected ( )
- abort ( )
- kill ( )


Question: Which of the following is true?

Choices:
- gets() doesn\'t do any array bound testing and should not be used.
- fgets() should be used in place of gets() only for files, otherwise gets() is fine
- gets() cannot read strings with spaces
- None of the above


Question:
Choose the best statement with respect to following three program snippets.

/*Program Snippet 1 with for loop*/

for (i = 0; i < 10; i++)

{

   /*statement1*/

   continue;

   /*statement2*/

}

/*Program Snippet 2 with while loop*/

i = 0;

while (i < 10)

{

   /*statement1*/

   continue;

   /*statement2*/

   i++;

}

/*Program Snippet 3 with do-while loop*/

i = 0;

do

{

   /*statement1*/

   continue;

   /*statement2*/

   i++;

}while (i < 10);

``````C

Choices:
- All the loops are equivalent i.e. any of the three can be chosen and they all will perform exactly same.
- continue can't be used with all the three loops in C.
- After hitting the continue; statement in all the loops, the next expression to be executed would be controlling expression (i.e. i < 10) in all the 3 loops.
- None of the above is correct.


Question: Which of the following statement is correct for switch controlling expression?

Choices:
- Only int can be used in “switch” control expression.
- Both int and char can be used in “switch” control expression.
- All types i.e. int, char and float can be used in “switch” control expression.
- “switch” control expression can be empty as well.


Question: Which of the following operators cannot be overloaded in C/C++ ?

Choices:
- Bitwise right shift assignment
- Address of
- Indirection
- Structure reference


Question:
With respect to following “for” loops in C, pick the best statement   Assume that there is a prior declaration of \'i\' in all cases

for (i < 10; i = 0 ; i++) // (i)

for (i < 10; i++ ; i = 0) // (ii)

for (i = 0; i < 10 ; i++) // (iii)

for (i = 0; i++ ; i < 10) // (iv)

for (i++; i = 0 ; i < 10) // (v)

for (i++; i < 0 ; i = 10) // (vi)

``````C

Choices:
- All the above “for” loops would compile successfully.
- All the above “for” loops would compile successfully. Except (iii), the behaviour of all the other “for” loops depend on compiler implementation.
- Only (iii) would compile successfully.
- Only (iii) and (iv) would compile successfully.
- Only (iii) and (iv) would compile successfully but  behaviour of (iv) would depend on compiler implementation.


Question:
Which combination of the integer variables x, y and z makes the variable a get the value 4 in the following expression?

a = ( x > y ) ? (( x > z ) ? x : z) : (( y > z ) ? y : z )

``````C

Choices:
- x = 3, y = 4, z = 2
- x = 6, y = 5, z = 3
- x = 6, y = 3, z = 5
- x = 5, y = 4, z = 5


Question:
What will be the output of the following C code?

#include <stdio.h>
int main()
{
int i;
for ( i=0; i<5; i++ )
{
   int i = 10;
   printf ( \"%d \", i );
   i++;
}
return 0;
}

``````C

Choices:
- 10 11 12 13 14
- 10 10 10 10 10
- 0 1 2 3 4
- Compilation error


Question:
#include<stdio.h>
int main()
{
    int a = 5;
    switch(a)
    {
    default:
        a = 4;
    case 6:
        a--;
    case 5:
        a = a+1;
    case 1:
        a = a-1;
    }
    printf(\"%d \\n\", a);
    return 0;
}

``````C

Choices:
- 3
- 4
- 5
- None of these


Question:
Output of following C code will be?

#include <stdio.h>
#include <stdlib.h>

int top = 0;

char fun1()
{
    char a[] = {'a', 'b', 'c', '(', 'd'};
    return a[top++];
}

int main()
{
    char b[10];
    char ch2;
    int i = 0;

    while ((ch2 = fun1()) != '(')
    {
        b[i++] = ch2;
    }

    b[i] = '\0'; // Add null-terminating character to mark the end of the string

    printf("%s", b);

    return 0;
}

``````C

Choices:
- abc(
- abc
- 3 special characters with ASCII value 1
- Empty String


Question:
Output of following C code will be?

#include <stdio.h>
int main()
{
   int a = 0;
   int b;
   a = (a == (a == 1));
   printf("%d", a);
   return 0;
}

``````C

Choices:
- 0
- 1
- Big negative number
- -1


Question:
Consider the following ANSI C function:

int SimpleFunction(int Y[], int n, int x)
{
int total = Y[0], loopIndex;
for (loopIndex=1; loopIndex<=n-1; loopIndex++)
    total=x*total +Y[loopIndex];
return total;
}

Let Z be an array of 10 elements with Z[i]=1, for all i such that 0?i?9. The value returned by SimpleFunction(Z,10,2) is __________ .

Choices:
- 1023
- 1024
- 2047
- 511


Question:
Output of following C code will be?

#include <stdio.h>

int main() {
   int y = 0;
   int x = (y != 0);
   printf("%d", x);
   return 0;
}

``````C

Choices:
- 0
- 1
- A bog negative Number
- Compiler Error


Question:
Choose the correct output from the options given below:

#include‹stdio.h›
int main()
{
    struct site
    {
        char name[] = \"GeeksQuiz\";
        int no_of_pages = 200;
    };
    struct site *ptr;
    printf(\"%d \", ptr->no_of_pages);
    printf(\"%s\", ptr->name);
    getchar();
    return 0;
}

``````C

Choices:
- 200 GeeksQuiz
- 200
- Runtime Error
- Compiler Error


Question:
The following C declarations

struct node
{
   int i;
   float j;
};
struct node *s[10] ;

``````C

define s to be

Choices:
- An array, each element of which is a pointer to a structure of type node
- A structure of 2 fields, each field being a pointer to an array of 10 elements
- A structure of 3 fields: an integer, a float, and an array of 10 elements
- An array, each element of which is a structure of type node.


Question:
Consider the following C program.

#include <stdio.h>

int main()
{
    int i, j, count;
    count = 0;
    i = 0;

    for (j = -3; j <= 3; j++)
    {
        if ((j >= 0) && (i++))
        {
            count = count + j;
        }
    }

    count = count + i;
    printf("%d", count);

    return 0;
}

``````C

Which one of the following options is correct?

Choices:
- The program will not compile successfully
- The program will compile successfully and output 10 when executed
- The program will compile successfully and output 8 when executed
- The program will compile successfully and output 13 when executed


Question:
Consider the following C functions.

int tob (int b, int* arr) {
    int i;
    for (i = 0; b>0; i++)  {
        if (b%2)  arr [i] = 1;
        else      arr[i] = 0;
        b = b/2;
    }
    return (i);
}

int pp(int a, int b)  {
    int  arr[20];
    int i, tot = 1, ex, len;
    ex = a;
    len = tob(b, arr);
    for (i=0; i<len ; i++) {
         if (arr[i] ==1)
             tot = tot * ex;
         ex= ex*ex;
    }
return (tot) ;
}

``````C

The value returned by pp(3,4) is ________ .

Note - This question was Numerical Type.

Choices:
- 81
- 64
- 100
- 49


Question: Why Java is Partially OOP language?

Choices:
- It allows code to be written outside classes
- It supports usual declaration of primitive data types
- It does not support pointers
- It doesn’t support all types of inheritance


Question:
What will be the output of the following ‘C’ code?

#include <stdio.h>

int main()
{
    int x = 128;
    printf("\n%d", 1 + x++);

    return 0;
}

``````C

Choices:
- 128
- 129
- 130
- 131


Question:
Output of following C code will be?

#include <stdio.h>

int main() {
    int x = 10;
    int y = (x++, x++, x++);
    printf("%d %d\n", x, y);
    return 0;
}

``````C

Choices:
- 13 12
- 13 13
- 10 10
- Compiler Dependent


Question:
#include <stdio.h>

int i;

int main() {
    if (i) {
        // Do nothing
    } else {
        printf("Else");
    }
    return 0;
}

``````C

What is correct about the above program?

Choices:
- if block is executed.
- else block is executed.
- It is unpredictable as i is not initialized.
- Error: misplaced else


Question:
Consider the following ANSI C program.

#include < stdio.h >
int main( )
{
    int arr[4][5];
    int  i, j;
    for (i=0; i<4; i++)
    ??????{
        for (j=0; j<5; j++)
        {
            arr[i][j] = 10 * i + j;
        }
    }
    printf("%d", *(arr[1]+9));
    return 0;
}

What is the output of the above program?

Choices:
- 14
- 20
- 24
- 30


Question:
Consider the following ANSI C program

#include
int foo(int x, int y, int q)
    {
        if ((x<=0) && (y<=0))
        return q;
        if (x<=0)
        return foo(x, y-q, q);
        if (y<=0)
        return foo(x-q, y, q);
        return foo(x, y-q, q) + foo(x-q, y, q);
    }
int main( )
{
    int r = foo(15, 15, 10);
    printf(“%d”, r);
    return 0;
}

The output of the program upon execution is _________ .

Choices:
- 60
- 10
- 15
- 50


Question:
What does the following program do when the input is unsigned 16-bit integer?
#include
main( )
{
unsigned int num;
int i;
scanf (“%u”, &num);
for ( i = 0; i<16; i++)
{
printf (“%d”, (num << i & 1 << 15 ) ? 1:0);
}
}

Choices:
- It prints all even bits from num
- It prints all odd bits from num
- It prints binary equivalent of num
- None of the above


Question:
The below program would give compile error because comma has been used after foo(). Instead, semi-colon should be used i.e. the way it has been used after bar().

That\'s why if we use semi-colon after foo(), the program would compile and run successfully while printing "GeeksQuiz"

#include \"stdio.h\"

void foo(void)
{
 printf(\"Geeks\");
}
void bar(void)
{
 printf(\"Quiz\");
}

int main()
{
 foo(), bar();
 return 0;
}

``````C

Choices:
- TRUE
- FALSE


Question:
#include <stdio.h>

int main()
{
  printf(\" \\\"GEEKS %% FOR %% GEEKS\\\"\");
  getchar();
  return 0;
}

``````C

Choices:
- “GEEKS % FOR % GEEKS”
- GEEKS % FOR % GEEKS
- \\"GEEKS %% FOR %% GEEKS\\"
- GEEKS %% FOR %% GEEKS


Question: What is the output of the below code int i = 0;while(i<n){if(i%2)break;i++;}cout<<i;

Choices:
- 1
- 0
- n
- n-1


Question:
Predict output of the following program

#include <stdio.h>
int main()
{
   printf("\new_c_question\b\r");
   printf("geeksforgeeks");
   getchar();
   return 0;
}

``````C

Choices:
- ew_c_questiongeeksforgeeks
- new_c_quesgeeksforgeeks
- geeksforgeeks
- Depends on terminal configuration


Question: fggbb

Choices:
- a
- s
- c
- g


Question:
Consider the following ANSI C function:

int SomeFunction (int x, int y)
{
    if ((x==1) || (y==1)) return 1;
    if (x==y) return x;
    if (x > y) return SomeFunction(x-y, y);
    if (y > x) return SomeFunction (x, y-x);

}

The value returned by SomeFunction(15, 255) is __________ .

Choices:
- 15
- 1275
- 30
- 255


Question:
What’s going to happen when we compile and run the following C program?

#include < stdio.h >

int main()

{

 int j = 0;

 for ( ; j < 10 ; )

 {

   if (j < 10)

     printf(\"Geeks\", j++);

   else

     continue;

   printf(“Quiz”);

 }

 return 0;

}

``````C

Choices:
- Compile Error due to use of continue in for loop.
- No compile error but it will run into infinite loop printing Geeks.
- No compile error and it’ll print GeeksQuiz 10 times followed by Quiz once.
- No compile error and it’ll print GeeksQuiz 10 times.


Question:
With respect to following “for” loops in C, pick the best statement.  Assume that there is a prior declaration of \'i\' in all cases

for (i = 0; i < 10 ; i++) // (i)

for ( ; i < 10 ; i++) // (ii)

for (i = 0;  ; i++) // (iii)

for (i = 0; i < 10 ; ) // (iv)

for ( ; ; ) // (v)

``````C

Choices:
- Only (i) and (v) would compile successfully. Also (v) can be used as infinite loop.
- Only (i) would compile successfully.
- All would compile successfully but behavior of (ii), (iii) and (iv) would depend on compiler.
- All would compile successfully.


Question: Suppose a, b, c and d are int variables. For ternary operator in C ( ? : ), pick the best statement.

Choices:
- a>b ?  :   ; is valid statement i.e. 2nd and 3rd operands can be empty and they are implicitly replaced with non-zero value at run-time.
- a>b ? c=10 : d=10; is valid statement. Based on the value of a and b, either c or d gets assigned the value of 10.
- a>b ? (c=10,d=20) : (c=20,d=10); is valid statement. Based on the value of a and b, either c=10,d=20 gets executed or c=20,d=10 gets executed.
- All of the above are valid statements for ternary operator.


Question: For a given integer, which of the following operators can be used to “set” and “reset” a particular bit respectively?

Choices:
- | and &
- && and ||
- & and |
- || and &&


Question: In the context of modulo operation (i.e. remainder on division) for floating point (say 2.1 and 1.1), pick the best statement.

Choices:
- For floating point, modulo operation isn\'t defined and that\'s why modulo can\'t be found.
- (2.1 % 1.1) is the result of modulo operation.
- fmod(2.1,1.1) is the result of module operation.
- ((int)2.1) % ((int)1.1) is the result of modulo operation.


Question:
Predict the output of following program?

#include \"stdio.h\"
int main()
{
    char arr[100];
    printf(\"%d\", scanf(\"%s\", arr));
    /* Suppose that input value given
        for above scanf is \"GeeksQuiz\" */
    return 1;
}

``````C

Choices:
- 9
- 1
- 10
- 100


Question:
Consider the following C program.

#include <stdio.h>
struct Ournode {
  char x, y, z;
};

int main() {
  struct Ournode p = {\'1\', \'0\', \'a\' + 2};
  struct Ournode *q = &p;
  printf(\"%c, %c\", *((char *)q + 1), *((char *)q + 2));
  return 0;
}

``````C

The output of this program is:

Choices:
- 0, c
- 0, a+2
- \'0\', \'a+2\'
- \'0\', \'c\'


Question:
What’s going to happen when we compile and run the following C program?

#include < stdio.h >

int main()

{

  int i = 1, j;

  for ( ; ; )

  {

    if (i)

        j = --i;

    if (j < 10)

       printf(\"GeeksQuiz\", j++);

    else

       break;

  }

  return 0;

}

``````C

Choices:
- Compile Error.
- No compile error but it will run into infinite loop printing GeeksQuiz.
- No compile error and it’ll print GeeksQuiz 10 times.
- No compile error but it’ll print GeeksQuiz 9 times.


Question:
#include <stdio.h>

int main() {
    int i;
    if (printf("0"))
        i = 3;
    else
        i = 5;
    printf("%d", i);
    return 0;
}

``````C

Predict the output of above program?

Choices:
- 3
- 5
- 03
- 05


Question:
Consider the following ANSI C program:  int main () {
    Integer x;
    return 0;
}
Which one of the following phases in a seven-phase C compiler will throw an error?

Choices:
- Lexical analyzer
- Syntax analyzer
- Semantic analyzer
- Machine dependent optimizer


Question:
#include <stdio.h>

int main() {
    int i = 3;
    switch (i) {
        case 1:
            printf("Geeks");
            break;
        case 1+2:
            printf("Quiz");
            break;
        default:
            printf("GeeksQuiz");
    }
    return 0;
}

``````C

What is the output of the above program?

Choices:
- Geeks
- Quiz
- GeeksQuiz
- Compile-time error


Question:
#include <stdio.h>
int main()
{
    int arr[] = {1, 2, 3, 4, 5};
    int *p = arr;
    ++*p;
    p += 2;
    printf(\"%d\", *p);
    return 0;
}

``````C

Choices:
- 2
- 3
- 4
- Compiler Error


Question:
In below program, what would you put in place of “?” to print “Quiz”?

#include <stdio.h>
int main()
{
  char arr[] = \"GeeksQuiz\";
  printf(\"%s\", ?);
  return 0;
}

``````C

Choices:
- arr
- (arr+5)
- (arr+4)
- Not possible


Question:
#include <stdio.h>
void f(char**);
int main()
{
    char *argv[] = { \"ab\", \"cd\", \"ef\", \"gh\", \"ij\", \"kl\" };
    f(argv);
    return 0;
}
void f(char **p)
{
    char *t;
    t = (p += sizeof(int))[-1];
    printf(\"%s\\n\", t);
}

``````C

Choices:
- ab
- cd
- ef
- gh


Question:
What does the following C-statement declare? [1 mark]

int ( * f) (int * ) ;

``````C

Choices:
- A function that takes an integer pointer as argument and returns an integer.
- A function that takes an integer as argument and returns an integer pointer.
- A pointer to a function that takes an integer pointer as argument and returns an integer.
- A function that takes an integer pointer as argument and returns a function pointer


Question:
Consider the C program shown below.

#include <stdio.h>
#define print(x) printf(\"%d \", x)
int x;
void Q(int z)
{
    z += x;
    print(z);
}
void P(int *y)
{
    int x = *y + 2;
    Q(x);
    *y = x - 1;
    print(x);
}
main(void)
{
    x = 5;
    P(&x);
    print(x);
}

``````C

The output of this program is

Choices:
- 12 7 6
- 22 12 11
- 14 6 6
- 7 6 6


Question:
Suppose that in a C program snippet, followings statements are used.

i) sizeof(int);
ii) sizeof(int*);
iii) sizeof(int**);

``````C

Assuming size of pointer is 4 bytes and size of int is also 4 bytes, pick the most correct answer from the given options.

Choices:
- Only i) would compile successfully and it would return size as 4.
- i), ii) and iii) would compile successfully and size of each would be same i.e. 4
- i), ii) and iii) would compile successfully but the size of each would be different and would be decided at run time.
- ii) and iii) would result in compile error but i) would compile and result in size as 4.


Question:
#include <stdio.h>

int main()
{
    int a[][] = {{1,2},{3,4}};
    int i, j;
    for (i = 0; i < 2; i++)
        for (j = 0; j < 2; j++)
            printf(\"%d \", a[i][j]);
    return 0;
}

``````C

Choices:
- 1 2 3 4
- Compiler Error in line " int a[][] = {{1,2},{3,4}};"
- 4 garbage values
- 4 3 2 1


Question:
#include<stdio.h>
int main()
{
    int a[10][20][30] = {0};
    a[5][2][1] = 2;
    return 0;
}

``````C

Which of the following will print the value 2 for the above code?

Choices:
- printf("%d",*(((a+5)+2)+1));
- printf("%d",***((a+5)+2)+1);
- printf("%d",*(*(*(a+5)+2)+1));
- None of these


Question:
#include <stdio.h>
int main()
{
    char p;
    char buf[10] = {1, 2, 3, 4, 5, 6, 9, 8};
    p = (buf + 1)[5];
    printf(\"%d\\n\", p);
    return 0;
}

``````C

Choices:
- 5
- 6
- 9
- None of the above


Question:
For a C program accessing X[i][j][k], the following intermediate code is generated by a compiler. Assume that the size of an integer is 32 bits and the size of a character is 8 bits.

  t0 = i ∗ 1024
  t1 = j ∗ 32
  t2 = k ∗ 4
  t3 = t1 + t0
  t4 = t3 + t2
  t5 = X[t4]

Which one of the following statements about the source code for the C program is CORRECT?

Choices:
- X is declared as “int X[32][32][8]”.
- X is declared as “int X[4][1024][32]”.
- X is declared as “char X[4][32][8]”.
- X is declared as “char X[32][16][2]”.


Question:
What’s the meaning of following declaration in C language?

int (*p)[5];

``````C

Choices:
- It will result in compile error because there shouldn\'t be any parenthesis i.e. “int *p[5]” is valid.
- p is a pointer to 5 integers.
- p is a pointer to integer array.
- p is an array of 5 pointers to integers.
- p is a pointer to an array of 5 integers


Question:
In a C file (say sourcefile1.c), an array is defined as follows. Here, we don’t need to mention array arr size explicitly in [] because the size would be determined by the number of elements used in the initialization.

int arr[] = {1,2,3,4,5};

``````C

In another C file (say sourcefile2.c), the same array is declared for usage as follows:

extern int arr[];

``````C

In sourcefile2.c, we can use sizeof() on arr to find out the actual size of arr.

Choices:
- TRUE
- FALSE


Question:
Find out the correct statement for the following program.

#include \"stdio.h\"

int * arrPtr[5];

int main()
{
 if(*(arrPtr+2) == *(arrPtr+4))
 {
   printf(\"Equal!\");
 }
 else
 {
  printf(\"Not Equal\");
 }
 return 0;
}

``````C

Choices:
- Compile Error
- It’ll always print Equal.
- It’ll always print Not Equal.
- Since elements of arrPtr aren’t initialized in the program, it’ll print either Equal or Not Equal.


Question:
Pick the best statement for the below:

int arr[50] = {0,1,2,[47]=47,48,49};

``````C

Choices:
- This isn’t allowed in C and it’ll give compile error
- This is allowed in C as per standard. Basically, it’ll initialize arr[0], arr[1], arr[2], arr[47], arr[48] and arr[49] to 0,1,2,47,48 and 49 respectively. The remaining elements of the array would be initialized to 0.


Question:
Pick the best statement for the below program:

#include \"stdio.h\"

void fun(int n)
{
   int idx;
   int arr1[n] = {0};
   int arr2[n];

   for (idx=0; idx<n; idx++)
       arr2[idx] = 0;
}

int main()
{
   fun(4);
   return 0;
}

``````C

Choices:
- Definition of both arr1 and arr2 is incorrect because variable is used to specify the size of array. That’s why compile error.
- Apart from definition of arr1 arr2, initialization of arr1 is also incorrect. arr1 can’t be initialized due to its size being specified as variable. That’s why compile error.
- Initialization of arr1 is incorrect. arr1 can’t be initialized due to its size being specified as variable. That’s why compile error.
- No compile error. The program would define and initializes both arrays to ZERO.


Question:
Pick the best statement for the below program:

#include \"stdio.h\"

int size = 4;
int arr[size];

int main()
{
 if(arr[0])
  printf(\"Initialized to ZERO\");
 else
  printf(\"Not initialized to ZERO\");

 return 0;
}

``````C

Choices:
- No compile error and it’ll print “Initialized to ZERO”.
- No compile error and it’ll print “Not initialized to ZERO”.
- Compile error because size of arr has been defined using variable outside any function.
- No compile error and it’ll print either “Initialized to ZERO” or “Not initialized to ZERO” depending on what value is present at arr[0] at a particular run of the program.


Question:
Consider the following C program.

void f(int, short);
void main()
{
  int i = 100;
  short s = 12;
  short *p = &s;
  __________ ;   // call to f()
}

``````C

Which one of the following expressions, when placed in the blank above, will NOT result in a type checking error?

Choices:
- f(s, *s)
- i = f(i,s)
- f(i,*s)
- f(i,*p)


Question:
Consider the C program given below :

 #include <stdio.h>
int main ()    {
    int sum = 0, maxsum = 0,  i,  n = 6;
    int a [] = {2, -2, -1, 3, 4, 2};
    for (i = 0; i < n; i++)    {
            if (i == 0 || a [i]  < 0  || a [i] < a [i - 1])  {
                     if (sum > maxsum) maxsum = sum;
                     sum = (a [i] > 0) ? a [i] : 0;
            }
            else sum += a [i];
    }
    if (sum > maxsum) maxsum = sum ;
    printf (\"%d\\n\", maxsum);

}

``````C

What is the value printed out when this program is executed?

Choices:
- 9
- 8
- 7
- 6


Question:
Let a and b be two sorted arrays containing n integers each, in non-decreasing order. Let c be a sorted array containing 2n integers obtained by merging the two arrays a and b. Assuming the arrays are indexed starting from 0, consider the following four statements  a[i] ≥ b [i] => c[2i] ≥ a [i] a[i] ≥ b [i] => c[2i] ≥ b [i] a[i] ≥ b [i] => c[2i] ≤ a [i] a[i] ≥ b [i] => c[2i] ≤ b [i]
Which of the following is TRUE?

Choices:
- only I and II
- only I and IV
- only II and III
- only III and IV


Question:
Let a be an array containing n integers in increasing order. The following algorithm determines whether there are two distinct numbers in the array whose difference is a specified number S > 0.

i = 0;
j = 1;
while (j < n )
{
    if (E) j++;
    else if (a[j] - a[i] == S) break;
    else i++;
}
if (j < n)
    printf(\"yes\")
else
   printf (\"no\");

``````C

Choose the correct expression for E.

Choices:
- a[j] - a[i]  >  S
- a[j] - a[i]  <  S
- a[i] - a[j]  <  S
- a[i] - a[j]  > S


Question:
Consider the following C program segment.

# include <stdio.h>
int main( )
{
    char s1[7] = \"1234\", *p;
    p = s1 + 2;
    *p = \'0\' ;
    printf (\"%s\", s1);
}

``````C

What will be printed by the program?

Choices:
- 12
- 120400
- 1204
- 1034


Question:
Consider the following code:

int a, b, c = 0;

void prtFun(void);

void main()
{
    static int a = 1;
    prtFun();
    a += 1;
    prtFun() printf("\n %d %d ", a, b);
}

void prtFun(void)
{
    static int a = 2;
    int b = 1;
    a += ++b;
    printf("\n %d %d ", a, b);
}

``````C++

What output will be generated by the given code d\\segment if: Line 1 is replaced by “auto int a = 1;” Line 2 is replaced by “register int a = 2;” (GATE CS 2012)

Choices:
- 3 14 14 2
- 4 26 16 1
- 4 26 22 0
- 4 24 22 0


Question:
Consider the following C function:

int f(int n)
{
static int i = 1;
if(n >= 5) return n;
n = n+i;
i++;
return f(n);
}

The value returned by f(1) is

Choices:
- 5
- 6
- 7
- 8


Question:
#include<stdio.h>

void swap (char *x, char *y)
{
    char *t = x;
    x = y;
    y = t;
}

int main()
{
    char *x = \"geeksquiz\";
    char *y = \"geeksforgeeks\";
    char *t;
    swap(x, y);
    printf(\"(%s, %s)\", x, y);
    t = x;
    x = y;
    y = t;
    printf(\"\\n(%s, %s)\", x, y);
    return 0;
}

``````C

Choices:
-
(geeksquiz, geeksforgeeks)
(geeksforgeeks, geeksquiz)
-
(geeksforgeeks, geeksquiz)
(geeksquiz, geeksforgeeks)
-
(geeksquiz, geeksforgeeks)
(geeksquiz, geeksforgeeks)
-
(geeksforgeeks, geeksquiz)
(geeksforgeeks, geeksquiz)


Question:
Consider the following C code.
#include  #include
void main()
{
 double pi = 3.1415926535;
 int a = 1;
 int i;
 for(i=0; i < 3; i++)
 if(a = cos(pi * i/2) )
 printf("%d ",1);
 else printf("%d ", 0);
}

What would the program print?

Choices:
- 000
- 010
- 101
- 111


Question:
Consider the following C function
void swap ( int x, int y )
{
int tmp;
tmp = x;
x= y;
y = tmp;
}

In order to exchange the values of two variables a and b:

Choices:
- Call swap (a, b)
- Call swap (&a, &b)
- swap(a, b) cannot be used as it does not return any value
- swap(a, b) cannot be used as the parameters passed by value


Question:
Consider the function
int func(int num) {
int count = 0;
while(num) {
count++;
num >>= 1;
}
return(count) ;
}

For func(435) the value returned is

Choices:
- 9
- 8
- 0
- 10


Question:
Consider the function
int fun(x: integer)
{
If x > 100 then fun = x – 10;
else
fun = fun(fun(x + 11));
}

For the input x = 95, the function will return

Choices:
- 89
- 90
- 91
- 92


Question:
Consider the following program written in pseudo-code. Assume that x and y are integers.

Count (x, y) {
    if (y !=1 ) {
        if (x !=1) {
            print("*");
            Count (x/2, y);
        }
        else {
            y=y-1;
            Count (1024, y);
        }
    }
}

The number of times that the print
``````None
 statement is executed by the call Count(1024, 1024)
``````None
 is _______ .

Note -This was Numerical Type question.

Choices:
- 10230
- 10
- 1023
- 23010


Question: Given a boolean function f (x1, x2, ..., xn), which of the following equations is NOT true

Choices:
- f (x1, x2, ..., xn) = x1\'f(x1, x2, ..., xn) + x1f(x1, x2, ..., xn)
- f (x1, x2, ..., xn) = x2f(x1, x2, …, xn) + x2\'f(x1, x2, …,xn)
- f (x1, x2, ..., xn) = xn\'f(x1, x2, …, 0) + xnf(x1, x2, …,1)
- f (x1, x2, ..., xn) = f(0, x2, …, xn) + f(1, x2, .., xn)


Question:
Consider the following program:

int f(int *p, int n)
{
    if (n <= 1) return 0;
    else return max(f(p+1,n-1),p[0]-p[1]);
}
int main()
{
    int a[] = {3,5,2,6,4};
    printf(\"%d\", f(a,5));
}

``````C

Note: max(x,y) returns the maximum of x and y. The value printed by this program is

Choices:
- 2
- 3
- 4
- 5


Question:
Which of the following is/are side effects of scan conversion ?
a. Aliasing
b. Unequal intensity of diagonal lines
c. Overstriking in photographic applications
d. Local or Global aliasing

Choices:
- a and b
- a, b and c
- a, c and d
- a, b, c and d


Question:
Predict the output of following program

#include<stdio.h>
int main()
{
    int a = 12;
    void *ptr = (int *)&a;
    printf(\"%d\", *ptr);
    getchar();
    return 0;
}

``````C

Choices:
- 12
- Compiler Error
- Runt Time Error
- 0


Question: In C, static storage class cannot be used with:

Choices:
- Global variable
- Function parameter
- Function name
- Local variable


Question: If only one memory location is to be reserved for a class variable, no matter how many objects are instantiated, then the variable should be declared as

Choices:
- extern
- static
- volatile
- const


Question:
int main() {
    char p[]="geeksquiz";
    char t;
    int i,j;
    for(i=0,j=strlen(p);i!=j;i++,j--)
    {
        t=p[i];
        p[i]=p[j-i];
        p[j-i]=t;
    }
    printf("%s",p);

    return 0;
}

``````C

Output?

Choices:
- ziuqskeeg
- Nothing is printed on the screen
- geeksquiz
- gggggggg


Question:
Output of following program

#include <stdio.h>
int fun(char *p)
{
    if (p == NULL || *p == \'\\0\') return 0;
    int current = 1, i = 1;
    while (*(p+current))
    {
        if (p[current] != p[current-1])
        {
            p[i] = p[current];
            i++;
        }
        current++;
    }
    *(p+i)=\'\\0\';
    return i;
}

int main()
{
    char str[] = \"geeksskeeg\";
    fun(str);
    puts(str);
    return 0;
}

``````C

Choices:
- gekskeg
- geeksskeeg
- geeks
- Garbage Values


Question: The minimum positive integer p such that 3p modulo 17 = 1 is

Choices:
- 5
- 8
- 12
- 16


Question: The minimum frame size required for a CSMA/CD based computer network running at 1 Gbps on a 200m cable with a link speed of 2 × 108m/s is

Choices:
- 125 bytes
- 250 bytes
- 500 bytes
- None of these


Question: When a coin is tossed, the probability of getting a Head is p,0<p<1. Let N be the random variable denoting the number of tosses till the first Head appears, including the toss where the Head appears. Assuming that successive tosses are independent, the expected value of N is

Choices:
- 1/p
- 1/(1−p)
- 1/p2
- 1/(1−p2)


Question: Assume that 16-bit CPU is trying to access a double word stating at an odd address. How many memory operations are required to access the data?

Choices:
- 1
- 2
- 3
- 4


Question:
Output of following C program? Assume that all necessary header files are included

int main()
{
    char *s1 = (char *)malloc(50);
    char *s2 = (char *)malloc(50);
    strcpy(s1, \"Geeks\");
    strcpy(s2, \"Quiz\");
    strcat(s1, s2);
    printf(\"%s\", s1);
    return 0;
}

``````C

Choices:
- GeeksQuiz
- Geeks
- Geeks Quiz
- Quiz


Question: Which of the following has the compilation error in C?

Choices:
- int n = 17;
- char c = 99;
- float f = (float)99.32;
- <include>


Question:
What is the output of the following program?

#include <stdio.h>
int funcf (int x);
int funcg (int y);

main()
{
    int x = 5, y = 10, count;
    for (count = 1; count <= 2; ++count)
    {
        y += funcf(x) + funcg(x);
        printf (\"%d \", y);
    }
}

funcf(int x)
{
    int y;
    y = funcg(x);
    return (y);
}

funcg(int x)
{
    static int y = 10;
    y += 1;
    return (y+x);
}

``````C

Choices:
- 43 80
- 42 74
- 33 37
- 32 32


Question:
Pick the best statement for the following program.

#include \"stdio.h\"

int foo(int a)
{
 printf(\"%d\",a);
 return 0;
}

int main()
{
 foo;
 return 0;
}

``````C

Choices:
- It’ll result in compile error because foo is used without parentheses.
- No compile error and some garbage value would be passed to foo function. This would make foo to be executed with output “garbage integer”.
- No compile error but foo function wouldn’t be executed. The program wouldn\'t print anything.
- No compile error and ZERO (i.e. 0) would be passed to foo function. This would make foo to be executed with output 0.


Question:
Both of the following declarations for function pointers are equivalent. Second one (i.e. with typedef) looks cleaner.

/* First Declaration */
int (*funPtr1)(int), (*funPtr2)(int);

/* Second Declaration*/
typedef int (*funPtr)(int);
funPtr funPtr1, funPtr2;

``````C

Choices:
- TRUE
- FALSE


Question:
What’s going to happen when we compile and run the following C program snippet?

#include \"stdio.h\"
int main()
{
 int a = 10;

 printf(\"=%d %d=\",(a+1));

 return 0;
}

``````C

Choices:
- =11 0=
- =11 X= where X would depend on Compiler implementation
- Undefined behavior
- Compiler Error due to missing argument for second %d


Question:
What’s going to happen when we compile and run the following C program snippet?

#include \"stdio.h\"
int main()
{
 int a = 10;
 int b = 15;

 printf(\"=%d\",(a+1),(b=a+2));
 printf(\" %d=\",b);

 return 0;
}

``````C

Choices:
- =11 15=
- =11 12=
- Compiler Error due to (b=a+2) in the first printf().
- No compile error but output would be =11 X= where X would depend on compiler implementation.


Question:
The output of the following C program is __________.

void f1 (int a, int b)
{
  int c;
  c=a; a=b; b=c;
}
void f2 (int *a, int *b)
{
  int c;
  c=*a; *a=*b;*b=c;
}
int main()
{
  int a=4, b=5, c=6;
  f1(a, b);
  f2(&b, &c);
  printf (“%d”, c-a-b);
  return 0;
}

``````C

Choices:
- -5
- -4
- 5
- 3


Question:
What is the output printed by the following program?

#include<stdio.h>
int f(int n, int k)
{
    if (n == 0)
        return 0;
    else if (n % 2)
        return f(n/2, 2*k) + k;
    else return f(n/2, 2*k) - k;
}
int main ()
{
    printf(\"%d\", f(20, 1));
    return 0;
}

``````C

Choices:
- 5
- 8
- 9
- 20


Question:
Assume int is 4 bytes, char is 1 byte and float is 4 bytes. Also, assume that pointer size is 4 bytes (i.e. typical case)

char *pChar;
int *pInt;
float *pFloat;

sizeof(pChar);
sizeof(pInt);
sizeof(pFloat);

``````C

What’s the size returned for each of sizeof() operator?

Choices:
- 4 4 4
- 1 4 4
- 1 4 8
- None of the above


Question:
The output of following C program is

#include <stdio.h>
char str1[100];

char *fun(char str[])
{
    static int i = 0;
    if (*str)
    {
        fun(str+1);
        str1[i] = *str;
        i++;
    }
    return str1;
}

int main()
{
    char str[] = \"GATE CS 2015 Mock Test\";
    printf(\"%s\", fun(str));
    return 0;
}

``````C

Choices:
- GATE CS 2015 Mock Test
- tseT kcoM 5102 SC ETAG
- Nothing is printed on screen
- Segmentation Fault


Question: Pick the correct statement for const and volatile.

Choices:
- const is the opposite of volatile and vice versa.
- const and volatile can’t be used for struct and union.
- const and volatile can’t be used for enum.
- const and volatile can’t be used for typedef.
- const and volatile are independent i.e. it’s possible that a variable is defined as both const and volatile.


Question:
What is the output of the following program?  #include
int tmp=20;
main( )
{
printf("%d ",tmp);
func( );
printf("%d ",tmp);
}
func( )
{
static int tmp=10;
printf("%d ",tmp);
}

Choices:
- 20 10 10
- 20 10 20
- 20 20 20
- 10 10 10


Question: A language with string manipulation facilities uses the following operations. head(s)- returns the first character of the string s tail(s)- returns all but the first character of the string s concat(sl, s2)- concatenates string s1 with s2. The output of concat(head(s), head(tail(tail(s)))), where s is acbc is

Choices:
- ab
- ba
- ac
- as


Question:
Predict the output of following program, assume that a character takes 1 byte and pointer takes 4 bytes.

#include <stdio.h>
int main()
{
    char *str1 = \"GeeksQuiz\";
    char str2[] = \"GeeksQuiz\";

    printf(\"sizeof(str1) = %d, sizeof(str2) = %d\",
           sizeof(str1), sizeof(str2));

    return 0;
}

``````C

Choices:
- sizeof(str1) = 10, sizeof(str2) = 10
- sizeof(str1) = 4, sizeof(str2) = 10
- sizeof(str1) = 4, sizeof(str2) = 4
- sizeof(str1) = 10, sizeof(str2) = 4


Question:
Predict the output of the below program:

#include <stdio.h>

#define EVEN 0
#define ODD 1

int main() {
    int i = 3;
    switch (i % 2) {
        case EVEN:
            printf("Even");
            break;
        case ODD:
            printf("Odd");
            break;
        default:
            printf("Default");
    }
    return 0;
}

``````C

Choices:
- Even
- Odd
- Default
- Compile-time error


Question:
Consider the following C program.

#include <stdio.h>
struct Ournode {
  char x, y, z;
};

int main() {
  struct Ournode p = {\'1\', \'0\', \'a\' + 2};
  struct Ournode *q = &p;
  printf(\"%c, %c\", *((char *)q + 1), *((char *)q + 2));
  return 0;
}

``````C

The output of this program is:

Choices:
- 0, c
- 0, a+2
- \'0\', \'a+2\'
- \'0\', \'c\'


Question:
int f(int x, int *py, int **ppz)
{
  int y, z;
  **ppz += 1;
   z  = **ppz;
  *py += 2;
   y = *py;
   x += 3;
   return x + y + z;
}

void main()
{
   int c, *b, **a;
   c = 4;
   b = &c;
   a = &b;
   printf(\"%d \", f(c, b, a));
   return 0;
}

``````C

Choices:
- 18
- 19
- 21
- 22


Question:
Consider the following function written in the C programming language.

The output of the above function on input “ABCD EFGH” is

void foo (char *a)
{
  if (*a && *a != ` `)
  {
     foo(a+1);
     putchar(*a);
  }
}

``````C

Choices:
- ABCD EFGH
- ABCD
- HGFE DCBA
- DCBA


Question:
Consider this C code to swap two integers and these five statements after it:

void swap(int *px, int *py)
{
   *px = *px - *py;
   *py = *px + *py;
   *px = *py - *px;
}

``````C

S1: will generate a compilation error
S2: may generate a segmentation fault at runtime depending on the arguments passed
S3: correctly implements the swap procedure for all input pointers referring to integers stored in memory locations accessible to the process
S4: implements the swap procedure correctly for some but not all valid input pointers
S5: may add or subtract integers and pointers.

Choices:
- S1
- S2 and S3
- S2 and S4
- S2 and S5


Question: Which of the following is not a storage class specifier in C?

Choices:
- auto
- register
- static
- extern
- volatile


Question:
Consider the following pseudocode: x : integer := 1
 y : integer := 2
 procedure add
 x := x + y

 procedure second (P: procedure)
 x : integer := 2
 P()
 procedure first
 y : integer := 3
 second(add)
 first()
 write_integer (x)
What does it print if the language uses dynamic scoping with deepbinding?

Choices:
- 2
- 3
- 4
- 5


Question:
Consider the following code fragment
void foo(int x, int y)
{
x+=y;
y+=x;
}
main()
{
int x=5.5;
foo(x,x);
}
What is the final value of x in both call by value and call by reference, respectively?

Choices:
- 5 and 16
- 5 and 12
- 5 and 20
- 12 and 20


Question:
The following program
main()
{
inc(); inc(); inc();
}
inc()
{
static int x;
printf("%d", ++x);
}

Choices:
- prints 012
- prints 123
- prints 3 consecutive, but unpredictable numbers
- prints 111


Question: Which of the following storage classes have global visibility in C/C++ ?

Choices:
- Auto
- Extern
- Static
- Register


Question:
Pick the best statement for the following program snippet:

#include \"stdio.h\"
void foo(void)
{
 static int staticVar;
 staticVar++;
 printf(\"foo: %d\\n\",staticVar);
}

void bar(void)
{
 static int staticVar;
 staticVar++;
 printf(\"bar: %d\\n\",staticVar);
}

int main()
{
 foo(), bar(), foo();
 return 0;
}

``````C

Choices:
- Compile error because same static variable name is used in both foo and bar. Since these static variables retain their values even after function is over, same name can’t be used in both the functions.
- Compile error because semicolon isn’t used while calling foo() and bar() in side main function.
- No compile error and only one copy of staticVar would be used across both the functions and that’s why final value of that single staticVar would be 3.
- No compile error and separate copies of staticVar would be used in both the functions. That’s why staticVar in foo() would be 2 while staticVar in bar() would be 1.


Question:
#include<stdio.h>
void f(int *p, int *q)
{
  p = q;
  *p = 2;
}
int i = 0, j = 1;
int main()
{
  f(&i, &j);
  printf(\"%d %d", i, j);
  getchar();
  return 0;
}

``````C

Choices:
- 2 2
- 2 1
- 0 1
- 0 2


Question:
In the below statement, ptr1 and ptr2 are uninitialized pointers to int i.e. they are pointing to some random address that may or may not be valid address.

int* ptr1, ptr2;

``````C

Choices:
- TRUE
- FALSE


Question:
Assume that a character takes 1 byte. Output of following program?

#include<stdio.h>
int main()
{
    char str[20] = \"GeeksQuiz\";
    printf (\"%d\", sizeof(str));
    return 0;
}

``````C

Choices:
- 9
- 10
- 20
- Garbage Value


Question:
What will be the output produced by the following C code:

int main()
{
    int array[5][5];
    printf("%d",( (array == *array) && (*array == array[0]) ));
    return 0;
}

Choices:
- 1
- 0
- 2
- -1


Question:
For the following declaration of a function in C, pick the best statement

int [] fun(void (*fptr)(int *));

``````C

Choices:
- It will result in compile error.
- No compile error. fun is a function which takes a function pointer fptr as argument and return an array of int.
- No compile error. fun is a function which takes a function pointer fptr as argument and returns an array of int. Also, fptr is a function pointer which takes int pointer as argument and returns void.
- No compile error. fun is a function which takes a function pointer fptr as argument and returns an array of int. The array of int depends on the body of fun i.e. what size array is returned. Also, fptr is a function pointer which takes int pointer as argument and returns void.


Question: Which of the following is true about arrays in C?

Choices:
- For every type T, there can be an array of T.
- For every type T except void and function type, there can be an array of T.
- When an array is passed to a function, C compiler creates a copy of array.
- 2D arrays are stored in column major form


Question: A one dimensional array A has indices 1....75. Each element is a string and takes up three memory words. The array is stored at location 1120 decimal. The starting address of A[49] is

Choices:
- 1267
- 1164
- 1264
- 1169


Question: Consider the array A[]= {6,4,8,1,3} apply the insertion sort to sort the array . Consider the cost associated with each sort is 25 rupees , what is the total cost of the insertion sort when element 1 reaches the first position of the array  ?

Choices:
- 50
- 25
- 75
- 100


Question:
C program is given below:

# include <stdio.h>
int main ()
{
        int i, j;
        char a [2] [3] = {{\'a\', \'b\', \'c\'}, {\'d\', \'e\', \'f\'}};
        char b [3] [2];
        char *p = *b;
        for (i = 0; i < 2; i++) {
              for (j = 0; j < 3; j++) {
              *(p + 2*j + i) = a [i] [j];
              }
        }
}
 /* Add code here. Remove these lines if not writing code */

``````C

What should be the contents of the array b at the end of the program?

Choices:
-
a    b
c    d
e    f
-
a    d
b    e
c    f
-
a    c
e    b
d    f
-
a    e
d    c
b    f


Question:
Output of following C program?

#include<stdio.h>
#define max abc
#define abc 100

int main()
{
    printf(\"maximum is %d\", max);
    return 0;
}

``````C

Choices:
- maximum is 100
- abcimum is 100
- 100imum is 100
- abcimum is abc


Question:
In C, 1D array of int can be defined as follows and both are correct.

int array1D[4] = {1,2,3,4};
int array1D[] = {1,2,3,4};

``````C

But given the following definitions (along-with initialization) of 2D arrays

int array2D[2][4] = {1,2,3,4,5,6,7,8}; /* (i) */
int array2D[][4] = {1,2,3,4,5,6,7,8}; /* (ii) */
int array2D[2][] = {1,2,3,4,5,6,7,8}; /* (iii) */
int array2D[][] = {1,2,3,4,5,6,7,8}; /* (iv) */

``````C

Pick the correct statements.

Choices:
- Only (i) is correct.
- Only (i) and (ii) are correct.
- Only (i), (ii) and (iii) are correct.
- All (i), (ii), (iii) and (iv) are correct.


Question:
Predict the output of following program?

#include <stdio.h>
#define MAX 1000
int main()
{
   int MAX = 100;
   printf(\"%d \", MAX);
   return 0;
}

``````C

Choices:
- 1000
- 100
- Compiler Error
- Garbage Value


Question:
#include <stdio.h>
#define a 10
int main()
{
  printf(\"%d \",a);

  #define a 50

  printf(\"%d \",a);
  return 0;
}

``````C

Choices:
- Compiler Error
- 10 50
- 50 50
- 10 10


Question:
Output?

# include <stdio.h>
# define scanf  \"%s Geeks Quiz \"
int main()
{
   printf(scanf, scanf);
   return 0;
}

``````C

Choices:
- Compiler Error
- %s Geeks Quiz
- Geeks Quiz
- %s Geeks Quiz  Geeks Quiz


Question:
#include <stdio.h>
#define square(x) x*x
int main()
{
  int x;
  x = 36/square(6);
  printf(\"%d\", x);
  return 0;
}

``````C

Choices:
- 1
- 36
- 0
- Compiler Error


Question:
#include <stdio.h>
#define ISEQUAL(X, Y) X == Y
int main()
{
    #if ISEQUAL(X, 0)
        printf(\"Geeks\");
    #else
        printf(\"Quiz\");
    #endif
    return 0;
}

``````C

Output of the above program?

Choices:
- Geeks
- Quiz
- Any of Geeks or Quiz
- Compile time error


Question:
#include <stdio.h>
#define X 3
#if !X
    printf(\"Geeks\");
#else
    printf(\"Quiz\");

#endif
int main()
{
        return 0;
}

``````C

Choices:
- Geeks
- Quiz
- Compiler Error
- Runtime Error


Question:
What is the output of following program?

#include <stdio.h>
#define macro(n, a, i, m) m##a##i##n
#define MAIN macro(n, a, i, m)

int MAIN()
{
    printf(\"GeeksQuiz\");
    return 0;
}

``````C

Choices:
- Compiler Error
- GeeksQuiz
- MAIN
- main


Question:
Output?

#include<stdio.h>
#define f(g,g2) g##g2
int main()
{
   int var12 = 100;
   printf(\"%d\", f(var,12));
   return 0;
}

``````C

Choices:
- 100
- Compiler Error
- 0
- 1


Question:
#include <stdio.h>
#define PRINT(i, limit) do \\
                        { \\
                            if (i++ < limit) \\
                            { \\
                                printf(\"GeeksQuiz\\n\"); \\
                                continue; \\
                            } \\
                        }while(1)

int main()
{
    PRINT(0, 3);
    return 0;
}

``````C

How many times GeeksQuiz is printed in the above program?

Choices:
- 1
- 3
- 4
- Compile-time error


Question:
The following function computes the maximum value contained in an integer array p[] of size n (n >= 1)

int max(int *p, int n)
{
    int a=0, b=n-1;
    while (__________)
    {
        if (p[a] <= p[b])
        {
            a = a+1;
        }
        else
        {
            b = b-1;
        }
    }
    return p[a];
}

``````C

The missing loop condition is

Choices:
- a != n
- b != 0
- b > (a + 1)
- b != a


Question:
Choose the correct output from the options given below:

#include<stdio.h>
struct st
{
    int x;
    struct st next;
};

int main()
{
    struct st temp;
    temp.x = 10;
    temp.next = temp;
    printf(\"%d\", temp.next.x);
    return 0;
}

``````C

Choices:
- Compiler Error
- 10
- Runtime Error
- Garbage Value


Question:
What is the output of the below program?

#include <stdio.h>

int main() {
    int i = 2;
    switch (i) {
        case 0:
            printf("Geeks");
            break;
        case 1:
            printf("Quiz");
            break;
        default:
            printf("GeeksQuiz");
    }
    return 0;
}

``````C

Choices:
- Geeks
- Quiz
- GeeksQuiz
- Compile-time error


Question:
Consider the following C program.

#include<stdio.h>
void mystery(int *ptra, int *ptrb)
{
   int *temp;
   temp = ptrb;
   ptrb = ptra;
   ptra = temp;
}
int main()
{
    int a=2016, b=0, c=4, d=42;
    mystery(&a, &b);
    if (a < c)
       mystery(&c, &a);
    mystery(&a, &d);
    printf(\"%d", a);
}

``````C

The output of the program _____________   Note : This question was asked as Numerical Answer Type.

Choices:
- 2016
- 0
- 4
- 8


Question:
#include <stdio.h>
#define PRINT(i, limit) do \\
                        { \\
                            if (i++ < limit) \\
                            { \\
                                printf(\"GeeksQuiz\\n\"); \\
                                continue; \\
                            } \\
                        }while(0);

int main()
{
    int i = 0;
    PRINT(i, 3);
    return 0;
}

``````C

How many times GeeksQuiz is printed in the above program ?

Choices:
- 1
- 3
- 4
- Compile-time error


Question:
#include <stdio.h>

int main()
{
    int i = 1024;
    for (; i; i >>= 1)
        printf(\"GeeksQuiz\");
    return 0;
}

``````C

How many times will GeeksQuiz be printed in the above program?
``````C

``````C

``````C

Choices:
- 10
- 11
- Infinite
- The program will show compile-time error


Question:
What is printed by the following ANSI C program? #include<stdio.h>
int main(int argc, char *argv[])
{
   int x = 1, z[2] = {10, 11};
   int *p = NULL;
   p = &x;
   *p = 10;
   p = &z[1];
   *(&z[0] + 1) += 3;
   printf("%d, %d, %d\n", x, z[0], z[1]);
   return 0;
}

Choices:
- 1, 10, 11
- 1, 10, 14
- 10, 14, 11
- 10, 10, 14


Question: The following statement in ‘C’ int (*f())[ ]; declares

Choices:
- a function returning a pointer to an array of integers.
- a function returning an array of pointers to integers.
- array of functions returning pointers to integers.
- an illegal statement.


Question:
Assume that size of an integer is 32 bit.  What is the output of following program?

#include<stdio.h>
struct st
{
    int x;
    static int y;
};

int main()
{
    printf(\"%d\", sizeof(struct st));
    return 0;
}

``````C

Choices:
- 4
- 8
- Compiler Error
- Runtime Error


Question: What does the following expression means ? char ∗(∗(∗ a[N]) ( )) ( );

Choices:
- a pointer to a function returning array of n pointers to function returning character pointers.
- a function return array of N pointers to functions returning pointers to characters
- an array of n pointers to function returning pointers to characters
- an array of n pointers to function returning pointers to functions returning pointers to characters.


Question:
Anyone of the following can be used to declare a node for a singly linked list and “NODEPTR nodePtr;” can be used to declare pointer to a node using any of the following

/* First declaration */
typedef struct node
{
 int data;
 struct node *nextPtr;
}* NODEPTR;

/* Second declaration */
struct node
{
 int data;
 struct node * nextPtr;
};
typedef struct node * NODEPTR;

``````C

Choices:
- TRUE
- FALSE


Question:
Anyone of the followings can be used to declare a node for a singly linked list. If we use the first declaration, “struct node * nodePtr;” would be used to declare pointer to a node. If we use the second declaration, “NODEPTR nodePtr;” can be used to declare pointer to a node.

/* First declaration */
struct node {
int data;
struct node * nextPtr;
};

/* Second declaration */
typedef struct node{
int data;
NODEPTR nextPtr;
} * NODEPTR;

``````C

Choices:
- TRUE
- FALSE


Question:
Predict the output of following C program

#include<stdio.h>
struct Point
{
  int x, y, z;
};

int main()
{
  struct Point p1 = {.y = 0, .z = 1, .x = 2};
  printf(\"%d %d %d\", p1.x, p1.y, p1.z);
  return 0;
}

``````C

Choices:
- Compiler Error
- 2 0 1
- 0 1 2
- 2 1 0


Question:
# include <iostream>
# include <string.h>
using namespace std;

struct Test
{
  char str[20];
};

int main()
{
  struct Test st1, st2;
  strcpy(st1.str, \"GeeksQuiz\");
  st2 = st1;
  st1.str[0] = \'S\';
  cout << st2.str;
  return 0;
}

``````C

Choices:
- Segmentation Fault
- SeeksQuiz
- GeeksQuiz
- Compiler Error


Question:
union test
{
    int x;
    char arr[4];
    int y;
};

int main()
{
    union test t;
    t.x = 0;
    t.arr[1] = \'G\';
    printf(\"%s\", t.arr);
    return 0;
}

``````C

Predict the output of above program. Assume that the size of an integer is 4 bytes and size of character is 1 byte. Also assume that there is no alignment needed.

Choices:
- Nothing is printed
- G
- Garbage character followed by \'G\'
- Garbage character followed by \'G\', followed by more garbage characters
- Compiler Error


Question:
union test
{
    int x;
    char arr[8];
    int y;
};

int main()
{
    printf(\"%d\", sizeof(union test));
    return 0;
}

``````C

Predict the output of above program. Assume that the size of an integer is 4 bytes and size of character is 1 byte. Also assume that there is no alignment needed.

Choices:
- 12
- 16
- 8
- Compiler Error


Question:
In the following program snippet, both s1 and s2 would be variables of structure type defined as below and there won\'t be any compilation issue.

typedef struct Student
{
 int rollno;
 int total;
} Student;

Student s1;
struct Student s2;

``````C

Choices:
- TRUE
- FALSE


Question:
Assuming int size is 4 bytes, what is going to happen when we compile and run the following program?

#include “stdio.h”
int main()
{
  printf(“GeeksQuiz\\n”);
  main();
  return 0;
}

``````C

Choices:
- We can’t use main() inside main() and compiler will catch it by showing compiler error.
- GeeksQuiz would be printed in 2147483647 times i.e. (2 to the power 31) - 1.
- It’ll print GeeksQuiz infinite times i.e. the program will continue to run forever until it’s terminated by other means such as CTRL+C or CTRL+Z etc.
- GeeksQuiz would be printed only once. Because when main() is used inside main(), it’s ignored by compiler at run time. This is to make sure that main() is called only once.
- GeeksQuiz would be printed until stack overflow happens for this program.


Question:
struct node
{
   int i;
   float j;
};
struct node *s[10];

``````C

The above C declaration define \'s\' to be (GATE CS 2000)

Choices:
- An array, each element of which is a pointer to a structure of type node
- A structure of 2 fields, each field being a pointer to an array of 10 elements
- A structure of 3 fields: an integer, a float, and an array of 10 elements
- An array, each element of which is a structure of type node.


Question:
Pick the best statement for the following program snippet:

#include <stdio.h>

int main()
{
 int var;  /*Suppose address of var is 2000 */

 void *ptr = &var;
 *ptr = 5;
 printf(\"var=%d and *ptr=%d\",var,*ptr);

 return 0;
}

``````C

Choices:
- It will print “var=5 and *ptr=2000”
- It will print “var=5 and *ptr=5”
- It will print “var=5 and *ptr=XYZ” where XYZ is some random address
- Compile error


Question:
Consider the following C++ program\'

int a (int m)
{return ++m;}
int b(int&m)
{return ++m;}
int c(char &m)
{return ++m;}

void main 0
{
      int p = 0, q = 0, r = 0;
      p += a(b(p));
      q += b(a(q));
      r += a(c(r));
      cout<

Assuming the required header files are already included, the above program:

Choices:
- results in compilation error
- print 123
- print 111
- print 322


Question:
Consider the following table
  A. Activation record p. Linking loader   B. Location counter q. Garbage collection   C. Reference counts r. Subroutine call   D. Address relocation s. Assembler

Matching A, B, C, D in the same order gives :

Choices:
- p, q, r, s
- q, r, s, p
- r, s, q, p
- r, s, p, q


Question: ‘ptrdata’ is a pointer to a data type. The expression *ptrdata++ is evaluated as (in C++) :

Choices:
- Depends on compiler
- (*ptrdata)++
- *(ptrdata)++
- *(ptrdata++)


Question: Faster access to non-local variables is achieved using an array of pointers to activation records, called a

Choices:
- stack
- heap
- display
- activation tree


Question:
Consider the following snippet of a C program. Assume that swap(&x, &y) exchanges the contents of x and y.

int main()
{
    int array[] = {3, 5, 1, 4, 6, 2};
    int done = 0;
    int i;

    while (done == 0)
    {
        done  = 1;
        for (i = 0; i <= 4; i++)
        {
            if (array[i] < array[i+1])
            {
                swap(&array[i], &array[i+1]);
                done = 0;
            }
        }
        for (i = 5; i >= 1; i--)
        {
            if (array[i] > array[i-1])
            {
                swap(&array[i], &array[i-1]);
                done = 0;
            }
        }
    }

    printf("%d", array[3]);
}

The output of the program is _____.
Note: This question appeared as Numerical Answer Type.

Choices:
- 1
- 2
- 3
- 4


Question:
Consider the C program given below. What does it print?

#include <stdio.h>
int main ()
{
        int i, j;
        int a [8] = {1, 2, 3, 4, 5, 6, 7, 8};
        for(i = 0; i < 3; i++) {
             a[i] = a[i] + 1;
             i++;
        }
        i--;
        for (j = 7; j > 4; j--) {
              int i = j/2;
              a[i] = a[i] - 1;
        }
        printf (\"%d, %d\", i, a[i]);
}
 /* Add code here. Remove these lines if not writing code */

``````C

Choices:
- 2, 3
- 2, 4
- 3, 2
- 3, 3


Question:
What is the output of the following program ?

main (){
int x = 2, y = 5;
if(x < y) return (x = x + y);
else printf ("z1");
printf("z2");

Choices:
- z2
- z1z2
- Compilation error
- None of these


Question:
What is the output printed by the following C code?

# include <stdio.h>
int main ()
{
    char a [6] = \"world\";
    int i, j;
    for (i = 0, j = 5; i < j; a [i++] = a [j--]);
    printf (\"%s\\n\", a);
}
 /* Add code here. Remove these lines if not writing code */

``````C

Choices:
- dlrow
- Null String
- dlrld
- worow


Question: Let A(1:8, -5:5, -10:5) be a three dimensional array. How many elements are there in the array A?

Choices:
- 1200
- 1408
- 33
- 1050


Question:
Let A be a two dimensional array declared as follows:
A: array [1 ... 10] [1 ... 15] of integer;

Assuming that each integer takes one memory location, the array is stored in row-major order and the first element of the array is stored at location 100, what is the address of the element a[i][j] ?

Choices:
- 15i+ j+ 84
- 15j+ i+ 84
- 10i+ j+ 89
- 10j+ i+ 89


Question:
Consider the following C code

int main()
{
   int a = 300;
   char *b = (char *)&a;
   *++b = 2;
   printf("%d ",a);
   return 0;
}

Consider the size of int as two bytes and size of char as one byte. Predict the output of the following code .
Assume that the machine is little-endian.

Choices:
- 556
- 300
- Runtime Error
- Compile Time Error


Question:
What does the following program print?

#include
void f(int *p, int *q)
{
  p = q;
 *p = 2;
}
int i = 0, j = 1;
int main()
{
  f(&i, &j);
  printf(\"%d %d \\n\", i, j);
  getchar();
  return 0;
}

``````C

Choices:
- 2 2
- 2 1
- 0 1
- 0 2


Question: You are given an array A[] having n random bits and a function OR(i,j) which will take two indexes from an array as parameters and will return the result of ( A[i] OR A[j] ) i.e bitwise OR. What is the minimum no of OR calls required so as to determine all the bits inside the array i.e. to determine every index of A[] whether it has 0 or 1 ?

Choices:
- N-1
- N*(N-1)/2
- N
- Not possible to determine the bit array


Question: In an array of 2N elements that is both 2-ordered and 3-ordered, what is the maximum number of positions that an element can be from its position if the array were 1-ordered?

Choices:
- 1
- 2
- N/2
- 2N-1


Question:
Consider the following program

main()
{
int x = 1;
printf ("%d", (*char(char *)&x)) ;
}

Assuming required header files are included and if the machine in which this program is executed is little-endian, then the output will be

Choices:
- 0
- 99999999
- 1
- unpredictable


Question:
Consider the following function implemented in C:
void printxy(int x, int y)
{
    int *ptr;
    x = 0;
    ptr = &x;
    y = *ptr;
    *ptr = 1;
    printf("%d,%d", x, y);
}

The output of the printxy(1,1) is

Choices:
- 0,0
- 0,1
- 1,0
- 1,1


Question:
The following ‘C’ statement :
int * f [ ] ( );
declares:

Choices:
- A function returning a pointer to an array of integers.
- Array of functions returning pointers to integers.
- A function returning an array of pointers to integers.
- An illegal statement.


Question:
What will be the output of following C program?
main()
{
char g[] = "geeksforgeeks";
printf("%s", g + g[6] - g[8]);
}

Choices:
- geeks
- rgeeks
- geeksforgeeks
- forgeeks


Question: Which of the following is true with respect to Reference?

Choices:
- A reference can never be NULL
- A reference needs an explicit dereferencing mechanism
- A reference can be reassigned after it is established
- A reference and pointer are synonymous


Question:
The value printed by the following program is

void f(int* p, int m)
{
    m = m + 5;
    *p = *p + m;
    return;
}
void main()
{
    int i=5, j=10;
    f(&i, j);
    printf(\"%d\", i+j);
}

``````C

Choices:
- 10
- 20
- 30
- 40


Question:
Consider the following declaration:
int a, *b=&a, **c=&b;

The following program fragment
a=4;
**c=5;

Choices:
- does not change the value of a
- assigns address of c to a
- assigns the value of b to a
- assigns 5 to a


Question:
What is the output of this C code?

#include
void main()
{
int k=5;
int *p=&k;
int **m=&p;
printf("%d %d %d",k,*p,**m);
}

Choices:
- 5 5 5
- 5 5 junk
- 5 junk junk
- Compile time error


Question:
Consider the following C program

#include
main()
{
float sum = 0.0, j =1.0, i = 2.0;
while(i/j > 0.001) {
    j = j + 1;
    sum = sum + i/j;
    printf ( "%f\\n", sum );
    }
}

How many lines of output does this program produce?

Choices:
- 0-9 lines of output
- 10-19 lines of output
- 20-29 lines of output
- More than 29 lines of output


Question:
What does the following C-statement declare?
int (*f) (int*);

Choices:
- A function that takes an integer pointer as argument and returns an integer
- A function that takes an integer as argument and returns an integer pointer
- A pointer to a function that takes an integer pointer as argument and returns an integer
- A function that takes an integer pointer as argument and returns a function pointer


Question:
Consider the following C-program :

int fun(){  static int num = 16;  return num--;}int main(){  for(fun(); fun(); fun())    printf(\"%d \", fun());  return 0;}

``````C

What is output of above program?

Choices:
- Infinite loop
- 13 10 7 4 1
- 15 12 8 5 2
- 14 11 8 5 2


Question: Which one of the following is correct for overloaded functions in C++ ?

Choices:
- Compiler sets up a separate function for every definition of function.
- Compiler does not set up a separate function for every definition of function.
- Overloaded functions cannot handle different types of objects.
- Overloaded functions cannot have same number of arguments.


Question: Which of the following is true about return type of functions in C?

Choices:
- Functions can return any type
- Functions can return any type except array and functions
- Functions can return any type except array, functions and union
- Functions can return any type except array, functions, function pointer and union


Question: In C, parameters are always

Choices:
- Passed by value
- Passed by reference
- Non-pointer variables are passed by value and pointers are passed by reference
- Passed by value result


Question: Consider a Boolean function of ‘n’ variables. The order of an algorithm that determines whether the Boolean function produces a output 1 is

Choices:
- Logarithmic
- Linear
- Quadratic
- Exponential


Question:
Given below are three implementations of the swap( ) function in C++:
(a)
void swap (int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
}
int main( )
{
int p = 0, q = 1;
swap (p, q);
}

(b)

void swap (int &a, int &b)
{
int temp;
temp = a;
a = b;
b = temp;
}
int main( )
{
int p = 0, q = 1;
swap (p, q);
}

(c)

void swap (int * a, int * b)
{
int * temp;
temp = a;
a = b;
b = temp;
}
int main( )
{
int p = 0, q = 1;
swap (&p, &q);
}

Which of these would actually swap the contents of the two integer variables p and q?

Choices:
- (a) only
- (b) only
- (c) only
- (b) and (c) only


Question:
Consider the C program below. What does it print?

# include <stdio.h>
# define swapl (a, b) tmp = a; a = b; b = tmp
void swap2 ( int a, int b)
{
        int tmp;
        tmp = a; a = b; b = tmp;
 }
void swap3 (int*a, int*b)
{
        int tmp;
        tmp = *a; *a = *b; *b = tmp;
}
int main ()
{
        int num1 = 5, num2 = 4, tmp;
        if (num1 < num2) {swap1 (num1, num2);}
        if (num1 < num2) {swap2 (num1 + 1, num2);}
        if (num1 >= num2) {swap3 (&num1, &num2);}
        printf (\"%d, %d\", num1, num2);
}
 /* Add code here. Remove these lines if not writing code */

``````C

Choices:
- 5, 5
- 5, 4
- 4, 5
- 4, 4


Question: Which one of the following is correct, when a class grants friend status to another class?

Choices:
- The member functions of the class generating friendship can access the members of the friend class.
-
All member functions of the class granted friendship have unrestricted access to the
members of the class granting the friendship.
- Class friendship is reciprocal to each other.
- There is no such concept.


Question:
Predict the output of following program

#include <iostream>
using namespace std;
int main()
{
    const char* p = \"12345\";
    const char **q = &p;
    *q = \"abcde\";
    const char *s = ++p;
    p = \"XYZWVU\";
    cout << *++s;
    return 0;
}

``````CPP

Choices:
- Compiler Error
- c
- b
- Garbage Value


Question: If a function is friend of a class, which one of the following is wrong?

Choices:
- A function can only be declared a friend by a class itself.
- Friend functions are not members of a class, they are associated with it.
- Friend functions are members of a class.
- It can have access to all members of the class, even private ones.


Question:
#include<iostream>

using namespace std;
class P {
public:
   void print()  { cout <<\" Inside P\"; }
};

class Q : public P {
public:
   void print() { cout <<\" Inside Q\"; }
};

class R: public Q { };

int main(void)
{
  R r;
  r.print();
  return 0;
}

``````C

Choices:
- Inside P
- Inside Q
- Compiler Error: Ambiguous call to print()


Question:
Predict the output of following program.

#include <iostream>
using namespace std;
class Point
{
    int x, y;
public:
 Point(int i = 0, int j =0)
   { x = i; y = j;  }
   int getX() const { return x; }
   int getY() {return y;}
};

int main()
{
    const Point t;
    cout << t.getX() << \" \";
    cout << t.gety();
    return 0;
}

``````C

Choices:
- Garbage Values
- 0  0
- Compiler Error in line  cout << t.getX() << " ";
- Compiler Error in line  cout << t.gety();


Question:
#include <stdio.h>
int main()
{
   const int x;
   x = 10;
   printf(\"%d\", x);
   return 0;
}

``````C

Choices:
- Compiler Error
- 10
- 0
- Runtime Error


Question:
What happens in C++ when an exception is thrown and not caught anywhere like following program.

#include <iostream>
using namespace std;

int fun() throw (int)
{
    throw 10;
}

int main() {

  fun();

  return 0;
}

``````C

Choices:
- Compiler error
- Abnormal program termination
- Program doesn\'t print anything and terminates normally
- None of the above


Question:
In C++, const qualifier can be applied to
1) Member functions of a class
2) Function arguments
3) To a class data member which is declared as static
4) Reference variables

Choices:
- Only 1, 2 and 3
- Only 1, 2 and 4
- All
- Only 1, 3 and 4


Question:
Predict the output the of following program.

#include <iostream>
using namespace std;

class B;
class A {
    int a;
public:
    A():a(0) { }
    void show(A& x, B& y);
};

class B {
private:
    int b;
public:
    B():b(0) { }
    friend void A::show(A& x, B& y);
};

void A::show(A& x, B& y) {
    x.a = 10;
    cout << \"A::a=\" << x.a << \" B::b=\" << y.b;
}

int main() {
    A a;
    B b;
    a.show(a,b);
    return 0;
}

``````C

Choices:
- Compiler Error
- A::a=10 B::b=0
- A::a=0 B::b=0


Question:
#include<iostream>
using namespace std;

class Base {};

class Derived: public Base {};

int main()
{
    Base *bp = new Derived;
    Derived *dp = new Base;
}

``````C

Choices:
- No Compiler Error
- Compiler Error in line "Base *bp = new Derived;"
- Compiler Error in line  " Derived *dp = new Base;"
- Runtime Error


Question:
Output of following program?

#include <iostream>
#include<string>
using namespace std;

class Base
{
public:
    virtual string print() const
    {
        return \"This is Base class\";
    }
};

class Derived : public Base
{
public:
    virtual string print() const
    {
        return \"This is Derived class\";
    }
};

void describe(Base p)
{
    cout << p.print() << endl;
}

int main()
{
    Base b;
    Derived d;
    describe(b);
    describe(d);
    return 0;
}

``````CPP

Choices:
-
This is Derived class
This is Base class
-
This is Base class
This is Derived class
-
This is Base class
This is Base class
- Compiler Error


Question:
#include<iostream>
using namespace std;

class Base {
public:
    void fun()          {    cout << \"Base::fun() called\";     }
    void fun(int i)     {   cout << \"Base::fun(int i) called\";  }
};

class Derived: public Base  {
public:
    void fun()   {     cout << \"Derived::fun() called\";   }
};

int main()  {
    Derived d;
    d.Base::fun(5);
    return 0;
}

``````C

Choices:
- Compiler Error
- Base::fun(int i) called


Question:
#include<iostream>
using namespace std;

class Base
{
public:
    int fun()  { cout << \"Base::fun() called\"; }
    int fun(int i)  { cout << \"Base::fun(int i) called\"; }
};

class Derived: public Base
{
public:
    int fun() {  cout << \"Derived::fun() called\"; }
};

int main()
{
    Derived d;
    d.fun(5);
    return 0;
}

``````C

Choices:
- Base::fun(int i) called
- Derived::fun() called
- Base::fun() called
- Compiler Error


Question:
#include<iostream>
using namespace std;

class Base
{
public:
    void show()
    {
        cout<<\" In Base \";
    }
};

class Derived: public Base
{
public:
    int x;
    void show()
    {
        cout<<\"In Derived \";
    }
    Derived()
    {
        x = 10;
    }
};

int main(void)
{
    Base *bp, b;
    Derived d;
    bp = &d;
    bp->show();
    cout << bp->x;
    return 0;
}

``````C

Choices:
- Compiler Error in line " bp->show()"
- Compiler Error in line " cout << bp->x"
- In Base 10
- In Derived 10


Question:
Output?

#include<iostream>
using namespace std;

class Base {
private:
     int i, j;
public:
    Base(int _i = 0, int _j = 0): i(_i), j(_j) { }
};
class Derived: public Base {
public:
     void show(){
        cout<<\" i = \"<<i<<\"  j = \"<<j;
     }
};
int main(void) {
  Derived d;
  d.show();
  return 0;
}

``````C

Choices:
- i = 0 j = 0
- Compiler Error: i and j are private in Base
- Compiler Error: Could not call constructor of Base


Question:
Assume that an integer takes 4 bytes and there is no alignment in following classes, predict the output.

#include<iostream>
using namespace std;

class base {
    int arr[10];
};

class b1: public base { };

class b2: public base { };

class derived: public b1, public b2 {};

int main(void)
{
  cout << sizeof(derived);
  return 0;
}

``````C

Choices:
- 40
- 80
- 0
- 4


Question:
What happens when a function throws an error but doesn\'t specify it in the list of exceptions it can throw.

For example, what is the output of following program?

#include <iostream>
using namespace std;

// Ideally it should have been \"int fun() (int)\"
int fun()
{
    throw 10;
}

int main()
{
    try
    {
        fun();
    }
    catch (int )
    {
        cout << \"Caught\";
    }
    return 0;
}

``````CPP

Choices:
- Compiler Error
- No compiler Error. Output is "Caught"


Question:
Predict the output of following program.

#include <iostream>
using namespace std;
class A
{
protected:
    int x;
public:
    A() {x = 0;}
    friend void show();
};

class B: public A
{
public:
    B() : y (0) {}
private:
    int y;
};

void show()
{
    A a;
    B b;
    cout << \"The default value of A::x = \" << a.x << \" \";
    cout << \"The default value of B::y = \" << b.y;
}

``````CPP

Choices:
- Compiler Error in show() because x is protected in class A
- Compiler Error in show() because y is private in class b
- The default value of A::x = 0  The default value of B::y = 0
- Compiler Dependent


Question:
Output of C++ program?

#include <iostream>
int const s=9;
int main()
{
    std::cout << s;
    return 0;
}

``````C

Contributed by Pravasi Meet

Choices:
- 9
- Compiler Error


Question:
#include<iostream>
using namespace std;

class Base1
{
public:
    char c;
};

class Base2
{
public:
    int c;
};

class Derived: public Base1, public Base2
{
public:
    void show()  { cout << c; }
};

int main(void)
{
    Derived d;
    d.show();
    return 0;
}

``````CPP

Choices:
- Compiler Error in "cout << c;"
- Garbage Value
- Compiler Error in "class Derived: public Base1, public Base2"


Question:
Predict the output of following C++ program.  Assume that there is no alignment and a typical implementation of virtual functions is done by the compiler.

#include <iostream>
using namespace std;

class A
{
public:
    virtual void fun();
};

class B
{
public:
   void fun();
};

int main()
{
    int a = sizeof(A), b = sizeof(B);
    if (a == b) cout << \"a == b\";
    else if (a > b) cout << \"a > b\";
    else cout << \"a < b\";
    return 0;
}

``````C

Choices:
- a > b
- a == b
- a < b
- Compiler Error


Question:
What is the output of this C++ program?

#include
using namespace std;
void square (int *x)
{
*x = (*x)++ * (*x);
}
void square (int *x, int *y)
{
*x = (*x) * --(*y);
}
int main ( )
{
int number = 30;
square(&number, &number);
cout << number;
return 0;
}

Choices:
- 910
- 920
- 870
- 900


Question:
Output?

#include <iostream>
using namespace std;

class Base1 {
 public:
     ~Base1()  { cout << \" Base1\'s destructor\" << endl; }
};

class Base2 {
 public:
     ~Base2()  { cout << \" Base2\'s destructor\" << endl; }
};

class Derived: public Base1, public Base2 {
   public:
     ~Derived()  { cout << \" Derived\'s destructor\" << endl; }
};

int main()
{
   Derived d;
   return 0;
}

``````CPP

Choices:
-
Base1\'s destructor
Base2\'s destructor
Derived\'s destructor
-
Derived\'s destructor
Base2\'s destructor
Base1\'s destructor
- Derived\'s destructor
- Compiler Dependent


Question:
Output?

#include<iostream>
using namespace std;

int fun(int x = 0, int y = 0, int z)
{  return (x + y + z); }

int main()
{
   cout << fun(10);
   return 0;
}

``````CPP

Choices:
- 10
- 0
- 20
- Compiler Error


Question: What is the use of this pointer?

Choices:
- When local variable’s name is same as member’s name, we can access member using this pointer.
- To return reference to the calling object
- Can be used for chained function calls on an object
- All of the above


Question: Which of the following is true about this pointer?

Choices:
- It is passed as a hidden argument to all function calls
- It is passed as a hidden argument to all non-static function calls
- It is passed as a hidden argument to all static functions
- None of the above