Question:
In the context of the below program snippet, pick the best answer.

#include \"stdio.h\"
int arr[10][10][10];
int main()
{
 arr[5][5][5] = 123;
 return 0;
}

``````C

Which of the given printf statement(s) would be able to print arr[5][5][5]

(i) printf(\"%d\",arr[5][5][5]);
(ii) printf(\"%d\",*(*(*(arr+5)+5)+5));
(iii) printf(\"%d\",(*(*(arr+5)+5))[5]);
(iv) printf(\"%d\",*((*(arr+5))[5]+5));

``````C

Choices:
- only (i) would compile and print 123.
- both (i) and (ii) would compile and both would print 123.
- only (i), (ii) and (iii) would compile but only (i) and (ii) would print 123.
- only (i), (ii) and (iii) would compile and all three would print 123.
- all (i), (ii), (iii) and (iv) would compile but only (i) and (ii) would print 123.
- all (i), (ii), (iii) and (iv) would compile and all would print 123.


Question:
#include \"stdio.h\"
int main()
{
 void *pVoid;
 pVoid = (void*)0;
 printf(\"%lu\",sizeof(pVoid));
 return 0;
}

``````C

Pick the best statement for the above C program snippet.

Choices:
- Assigning (void *)0 to pVoid isn’t correct because memory hasn’t been allocated. That’s why no compile error but it\'ll result in run time error.
- Assigning (void *)0 to pVoid isn’t correct because a hard coded value (here zero i.e. 0) can’t assigned to any pointer. That’s why it\'ll result in compile error.
- No compile issue and no run time issue. And the size of the void pointer i.e. pVoid would equal to size of int.
- sizeof() operator isn’t defined for a pointer of void type.


Question:
#include \"stdlib.h\"
int main()
{
 int *pInt;
 int **ppInt1;
 int **ppInt2;

 pInt = (int*)malloc(sizeof(int));
 ppInt1 = (int**)malloc(10*sizeof(int*));
 ppInt2 = (int**)malloc(10*sizeof(int*));

 free(pInt);
 free(ppInt1);
 free(*ppInt2);
 return 0;
}

``````C

Choose the correct statement w.r.t. above C program.

Choices:
- malloc() for ppInt1 and ppInt2 isn’t correct. It’ll give compile time error.
- free(*ppInt2) is not correct. It’ll give compile time error.
- free(*ppInt2) is not correct. It’ll give run time error.
- No issue with any of the malloc() and free() i.e. no compile/run time error.


Question:
Consider the following C program.

# include
int main( )
{
  static int a[] = {10, 20, 30, 40, 50};
  static int *p[] = {a, a+3, a+4, a+1, a+2};
  int **ptr = p;
  ptr++;
  printf(\"%d%d\", ptr - p, **ptr};
}

``````C

The output of the program is _________

Choices:
- 140
- 120
- 100
- 40


Question:
What is the output of the following C code? Assume that the address of x is 2000 (in decimal) and an integer requires four bytes of memory.

#include <stdio.h>
int main()
{
   unsigned int x[4][3] = {{1, 2, 3}, {4, 5, 6},
                           {7, 8, 9}, {10, 11, 12}};
   printf(\"%u, %u, %u\", x+3, *(x+3), *(x+2)+3);
}

``````C

Choices:
- 2036, 2036, 2036
- 2012, 4, 2204
- 2036, 10, 10
- 2012, 4, 6


Question:
What will be output of the following program? Assume that you are running this program in little-endian processor.

#include<stdio.h>

int main() {
    short a = 320;
    char * ptr;
    ptr = (char * ) & a;
    printf(\"%d\", * ptr);
    return 0;
}

``````C

Choices:
- 1
- 320
- 64
- Compilation error


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:
Consider the following statements S1, S2 and S3 :
S1 : In call-by-value, anything that is passed into a function call is unchanged in the caller’s scope when the function returns.
S2 : In call-by-reference, a function receives implicit reference to a variable used as argument.
S3 : In call-by-reference, caller is unable to see the modified variable used as argument.

Choices:
- S3 and S2 are true.
- S3 and S1 are true.
- S2 and S1 are true.
- S1, S2, S3 are true.


Question: When an array is passed as parameter to a function, which of the following statements is correct?

Choices:
- The function can change values in the original array.
- In C, parameters are passed by value, the function cannot change the original value in the array.
- It results in compilation error when the function tries to access the elements in the array.
- Results in a run time error when the function tries to access the elements in the array.


Question:
Assume that the program ‘P’ is implementing parameter passing with ‘call by reference’.
What will be printed by following print statements in P?
Program P( )
{
x = 10;
y = 3;
funb (y, x, x)
print x;
print y;
}
funb (x, y, z)
{
y = y + 4;
z = x + y + z;
}

Choices:
- 10, 7
- 31, 3
- 10, 3
- 31, 7


Question:
Given i= 0, j = 1, k = – 1
x = 0.5, y = 0.0
What is the output of given ‘C’ expression ?
x * 3 & & 3 || j | k

Choices:
- -1
- 0
- 1
- 2


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:
What is printed by the following C program?

$include <stdio.h>
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));
   getchar();
}

``````C

Choices:
- 18
- 19
- 21
- 22


Question:
Consider the program below in a hypothetical language which allows global variable and a choice of call by reference or call by value methods of parameter passing.

 int i ;
program main ()
{
    int j = 60;
    i = 50;
    call f (i, j);
    print i, j;
}
procedure f (x, y)
{
    i = 100;
    x = 10;
    y = y + i ;
}

``````C

Which one of the following options represents the correct output of the program for the two parameter passing mechanisms?

Choices:
- Call by value : i = 70, j = 10; Call by reference : i = 60, j = 70
- Call by value : i = 50, j = 60; Call by reference : i = 50, j = 70
- Call by value : i = 10, j = 70; Call by reference : i = 100, j = 60
- Call by value : i = 100, j = 60; Call by reference : i = 10, j = 70


Question:
Predict the output of following C program

#include <stdio.h>
int main()
{
    char a = 012;

    printf(\"%d\", a);

    return 0;
}

``````C

Choices:
- Compiler Error
- 12
- 10
- Empty


Question: In C, sizes of an integer and a pointer must be same.

Choices:
- True
- False


Question:
Output?

int main()
{
    void *vptr, v;
    v = 0;
    vptr = &v;
    printf(\"%v\", *vptr);
    getchar();
    return 0;
}

``````C

Choices:
- 0
- Compiler Error
- Garbage Value


Question:
In the context of the following printf() in C, pick the best statement.

i) printf(\"%d\",8);
ii) printf(\"%d\",090);
iii) printf(\"%d\",00200);
iv) printf(\"%d\",0007000);

``````C

Choices:
- Only i) would compile. And it will print 8.
- Both i) and ii) would compile. i) will print 8 while ii) will print 90
- All i), ii), iii) and iv) would compile successfully and they will print 8, 90, 200 & 7000 respectively.
- Only i), iii) and iv) would compile successfully. They will print 8, 128 and 3584 respectively.


Question:
Predict the output of the following program:

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

``````C

Choices:
- G Q
- 71 81
- 71 Q
- Compile-time error


Question: As per C language standard, which of the followings is/are not keyword(s)? Pick the best statement. auto make main sizeof elseif

Choices:
- sizeof elseif make
- make main elseif
- make main
- auto make
- None of the above is keywords in C.


Question:
Consider the following program in a language that has dynamic seeping.
var x: real;
procedure show:
    begin print(x);end;
procedure small;
    var x: real;
        begin x: = 0.125; show; end;
begin x:=0.25
    show; small
    end.
Then the output of the program is:

Choices:
- 0.125 0.125
- 0.25 0.25
- 0.25 0.125
- 0.125 0.25


Question: Heap allocation is required for languages

Choices:
- that support recursion
- that support dynamic data structures
- that use dynamic scope rules
- none of the above


Question:
Output of following program

#include <stdio.h>
int fun(int n)
{
    static int s = 0;
    s = s + n;
    return (s);
}

int main()
{
    int i = 10, x;
    while (i > 0)
    {
        x = fun(i);
        i--;
    }
    printf (\"%d \", x);
    return 0;
}

``````C

Choices:
- 0
- 100
- 110
- 55


Question:
Output? (GATE CS 2012)

#include <stdio.h>
int a, b, c = 0;
void prtFun (void);
int main ()
{
    static int a = 1; /* line 1 */
    prtFun();
    a += 1;
    prtFun();
    printf ( \"\\n %d %d \" , a, b) ;
}

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

``````C

Choices:
-
3 1
4 1
4 2
-
4 2
6 1
6 1
-
4 2
6 2
2 0
-
3 1
5 2
5 2


Question:
Output?

#include <stdio.h>
int main()
{
  register int i = 10;
  int *ptr = &i;
  printf(\"%d\", *ptr);
  return 0;
}

``````C

Choices:
- Prints 10 on all compilers
- May generate compiler Error
- Prints 0 on all compilers
- May generate runtime Error


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

``````C

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


Question:
Output?

#include <stdio.h>

int main(void)
{
    int i = 10;
    const int *ptr = &i;
    *ptr = 100;
    printf(\"i = %d\\n\", i);
    return 0;
}

``````C

Choices:
- i = 100
- i = 10
- Compiler Error
- Runtime Error


Question:
#include <stdio.h>
char *fun()
{
    static char arr[1024];
    return arr;
}

int main()
{
    char *str = \"geeksforgeeks\";
    strcpy(fun(), str);
    str = fun();
    strcpy(str, \"geeksquiz\");
    printf(\"%s\", fun());
    return 0;
}

``````C

Choices:
- geeksforgeeks
- geeksquiz
- geeksforgeeks geeksquiz
- Compiler Error


Question:
Consider the following C function, what is the output?

#include <stdio.h>
int f(int n)
{
    static int r = 0;
    if (n <= 0) return 1;
    if (n > 3)
    {
        r = n;
        return f(n-2)+2;
    }
    return f(n-1)+r;
}

int main()
{
    printf(\"%d\", f(5));
}

``````C

Choices:
- 5
- 7
- 9
- 18


Question: In the context of C data types, which of the followings is correct?

Choices:
- “unsigned long long int” is a valid data type.
- “long long double” is a valid data type.
- “unsigned long double” is a valid data type.
- A), B) and C) all are valid data types.
- A), B) and C) all are invalid data types.


Question:
For the following “typedef” in C, pick the best statement

typedef int INT, *INTPTR, ONEDARR[10], TWODARR[10][10];

``````C

Choices:
- It will cause compile error because typedef is being used to define multiple aliases of incompatible types in the same statement.
- “INT x” would define x of type int. Remaining part of the statement would be ignored.
- “INT x” would define x of type int and “INTPTR y” would define pointer y of type int *. Remaining part of the statement would be ignored.
- “INT x” would define x of type int. “INTPTR y” would define pointer y of type int *. ONEDARR is an array of 10 int. TWODARR is a 2D array of 10 by 10 int.
- “INT x” would define x of type int. “INTPTR *y” would define pointer y of type int **. “ONEDARR  z” would define z as array of 10 int. “TWODARR t” would define t as array of 10 by 10 int.


Question:
Predict output of following program

int main()
{
    int i;
    int arr[5] = {1};
    for (i = 0; i < 5; i++)
        printf(\"%d \", arr[i]);
    return 0;
}

``````C

Choices:
- 1 followed by four garbage values
- 1 0 0 0 0
- 1 1 1 1 1
- 0 0 0 0 0


Question:
Predict the output of the below program:

#include <stdio.h>
#define SIZE(arr) sizeof(arr) / sizeof(*arr);
void fun(int* arr, int n)
{
    int i;
    *arr += *(arr + n - 1) += 10;
}

void printArr(int* arr, int n)
{
    int i;
    for(i = 0; i < n; ++i)
        printf(\"%d \", arr[i]);
}

int main()
{
    int arr[] = {10, 20, 30};
    int size = SIZE(arr);
    fun(arr, size);
    printArr(arr, size);
    return 0;
}

``````C

Choices:
- 20 30 40
- 20 20 40
- 50 20 40
- Compile-time error


Question:
Consider the following declaration of a ‘two-dimensional array in C:

 char a[100][100];

``````C

Assuming that the main memory is byte-addressable and that the array is stored starting from memory address 0, the address of a[40][50] is (GATE CS 2002)

Choices:
- 4040
- 4050
- 5040
- 5050


Question:
Assume the following C variable declaration

 int *A [10], B[10][10];

``````C

Of the following expressions
I A[2]
II A[2][3]
III B[1]
IV B[2][3]
which will not give compile-time errors if used as left hand sides of assignment statements in a C program (GATE CS 2003)?

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


Question:
Consider the following C-function in which a[n] and b[m] are two sorted integer arrays and c[n + m] be another integer array.

void xyz(int a[], int b [], int c[])
{
  int i, j, k;
  i = j = k = O;
  while ((i < n) && (j < m))
     if (a[i] < b[j]) c[k++] = a[i++];
     else c[k++] = b[j++];
}

``````C

Which of the following condition(s) hold(s) after the termination of the while loop? (GATE CS 2006) (i) j < m, k = n+j-1, and a[n-1] < b[j] if i = n (ii) i < n, k = m+i-1, and b[m-1] <= a[i] if j = m

Choices:
- only (i)
- only (ii)
- either (i) or (ii) but not both
- neither (i) nor (ii)


Question:
Output of following program?

#include<stdio.h>

int main()
{
  int a[] = {1, 2, 3, 4, 5, 6};
  int *ptr = (int*)(&a+1);
  printf(\"%d \", *(ptr-1) );
  return 0;
}

``````C

Choices:
- 1
- 2
- 6
- Runtime Error


Question:
Consider the following C program:

# include <stdio.h>
int main( )
{
   int i, j, k = 0;
   j = 2 * 3 / 4 + 2.0 / 5 + 8 / 5;
   k  -= --j;
   for (i = 0; i < 5; i++)
   {
      switch(i + k)
      {
         case 1:
         case 2: printf(\"\\n%d\", i + k);
         case 3: printf(\"\\n%d\", i + k);
         default: printf(\"\\n%d\", i + k);
      }
   }
   return 0;
}

``````C

The number of times printf statement is executed is __________.

Choices:
- 8
- 9
- 10
- 11


Question:
What is the output for a 64-bit Compiler?

# include <stdio.h>

void print(int arr[])
{
   int n = sizeof(arr)/sizeof(arr[0]);
   int i;
   for (i = 0; i < n; i++)
      printf("%d ", arr[i]);
}

int main()
{
   int arr[] = {1, 2, 3, 4, 5, 6, 7, 8};
   print(arr);
   return 0;
}

``````C

Choices:
- 1, 2, 3, 4, 5, 6, 7, 8
- Compiler Error
- 1 2
- Run Time Error


Question:
Predict the output of below program:

 #include <stdio.h>

int main()
{
	int arr[5];

	// Assume that base address of arr is 2000 and size of integer
        // is 32 bit
	arr++;
	printf(\"%u\", arr);

	return 0;
}

``````C

Choices:
- 2002
- 2004
- 2020
- lvalue required


Question:
In a C program snippet, followings are used for definition of Integer variables?

  signed s;
  unsigned u;
  long l;
  long long ll;

``````C

Pick the best statement for these.

Choices:
- All of the above variable definitions are incorrect because basic data type int is missing.
- All of the above variable definitions are correct because int is implicitly assumed in all of these.
- Only “long l;” and “long long ll;” are valid definitions of variables.
- Only “unsigned u;” is valid definition of variable.


Question: “typedef” in C basically works as an alias. Which of the following is correct for “typedef”?

Choices:
- typedef can be used to alias compound data types such as struct and union.
- typedef can be used to alias both compound data types and pointer to these compound types.
- typedef can be used to alias a function pointer.
- typedef can be used to alias an array.
- All of the above.


Question:
In a C program, following variables are defined:

 float      x = 2.17;
 double   y = 2.17;
 long double z = 2.17;

``````C

Which of the following is correct way for printing these variables via printf.

Choices:
- printf("%f %lf %Lf",x,y,z);
- printf(“%f %f %f”,x,y,z);
- printf("%f %ff %fff",x,y,z);
- printf("%f %lf %llf",x,y,z);


Question: Suppose a C program has floating constant 1.414, what\'s the best way to convert this as "float" data type?

Choices:
- (float)1.414
- float(1.414)
- 1.414f or 1.414F
- 1.414 itself of "float" data type i.e. nothing else required.


Question: Which of the followings is correct for a function definition along with storage-class specifier in C language?

Choices:
- int fun(auto int arg)
- int fun(static int arg)
- int fun(register int arg)
- int fun(extern int arg)
- All of the above are correct.


Question:
Predict the output of below program:

#include <stdio.h>

int main()
{
    int arr[5];
    // Assume base address of arr is 2000 and size of integer is 32 bit
    printf(\"%u %u\", arr + 1, &arr + 1);

    return 0;
}

``````C

Choices:
- 2004 2020
- 2004 2004
- 2004 Garbage value
- The program fails to compile because Address-of operator cannot be used with array name


Question: The C language is:

Choices:
- A context free language
- A context sensitive language
- A regular language
- Parsable fully only by a Turing machine


Question: Consider a program P that consists of two source modules M1 and M2 contained in two different files. If M1 contains a reference to a function defined in M2, the reference will be resolved at

Choices:
- Edit-time
- Compile-time
- Link-time
- Load-time


Question: The reason for using pointers in a C program is

Choices:
- Pointers allow different functions to share and modify their local variables.
- To pass large structures so that complete copy of the structure can be avoided.
- Pointers enable complex “linked" data structures like linked lists and binary trees.
- All of the above


Question:
#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:
In C, what is the meaning of following function prototype with empty parameter list

void fun()
{
   /* .... */
}

``````C

Choices:
- Function can only be called without any parameter
- Function can be called with any number of parameters of any types
- Function can be called with any number of integer parameters.
- Function can be called with one integer parameter.


Question:
What is the meaning of using static before function declaration?

For example following function sum is made static

static int sum(int x, int y, int z)
{
    return (x + y + z);
}

Choices:
- Static means nothing, sum() is same without static keyword.
- Function need not to be declared before its use
- Access to static functions is restricted to the file where they are declared
- Static functions are made inline


Question:
What is the meaning of using extern before function declaration?

For example following function sum is made extern

extern int sum(int x, int y, int z)
{
    return (x + y + z);
}

Choices:
- Function is made globally available
- extern means nothing, sum() is same without extern keyword.
- Function need not to be declared before its use
- Function is made local to the file.


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.

#include <stdio.h>

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?

#include <stdio.h>
int main()
{
    void demo();
    void (*fun)();
    fun = demo;
    (*fun)();
    fun();
    return 0;
}

void demo()
{
    printf(\"GeeksQuiz \");
}

``````C

Choices:
- GeeksQuiz
- GeeksQuiz  GeeksQuiz
- Compiler Error
- Blank Screen


Question:
Consider the following C-program:

void foo(int n, int sum)
{
  int k = 0, j = 0;
  if (n == 0) return;
    k = n % 10;
  j = n / 10;
  sum = sum + k;
  foo (j, sum);
  printf (\"%d,\", k);
}

int main ()
{
  int a = 2048, sum = 0;
  foo (a, sum);
  printf (\"%d\\n\", sum);

  getchar();
}

``````C

What does the above program print?

Choices:
- 8, 4, 0, 2, 14
- 8, 4, 0, 2, 0
- 2, 0, 4, 8, 14
- 2, 0, 4, 8, 0


Question:
Output of following program?

#include<stdio.h>

void dynamic(int s, ...)
{
    printf("%d", s);
}

int main()
{
    dynamic(2, 4, 6, 8);
    dynamic(3, 6, 9);
    return 0;
}

``````C

Choices:
- 2 3
- Compiler Error
- 4 3
- 3 2


Question:
What is the output of this program?

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

``````C

Choices:
- Address of main function
- Compiler Error
- Runtime Error
- Some random value


Question:
Output of following program?

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

``````C

Choices:
- 7 6 5
- 5 6 7
- 7 7 7
- Compiler Dependent


Question: Suppose n and p are unsigned int variables in a C program. We wish to set p to nC3. If n is large, which of the following statements is most likely to set p correctly?

Choices:
- p = n * (n-1) * (n-2) / 6;
- p = n * (n-1) / 2 * (n-2) / 3;
- p  = n * (n-1) / 3 * (n-2) / 2;
- p = n * (n-1) * (n-2) / 6.0;


Question:
Output of following program?

#include<stdio.h>
int main()
{
    float x = 0.1;
    if ( x == 0.1 )
        printf(\"IF\");
    else if (x == 0.1f)
        printf(\"ELSE IF\");
    else
        printf(\"ELSE\");
}

``````C

Choices:
- ELSE IF
- IF
- ELSE


Question:
#include <stdio.h>
int main()
{
    if (sizeof(int) > -1)
        printf(\"Yes\");
    else
        printf(\"No\");
    return 0;
}

``````C

Choices:
- Yes
- No
- Compiler Error
- Runtime Error


Question:
Assume that the size of char is 1 byte and negatives are stored in 2\'s complement form

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

``````C

Choices:
- 135
- +INF
- -121
- -8


Question:
Output?

#include <stdio.h>

int main()
{
    int (*ptr)(int ) = fun;
    (*ptr)(3);
    return 0;
}

int fun(int n)
{
  for(;n > 0; n--)
    printf(\"GeeksQuiz \");
  return 0;
}

``````C

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


Question:
Predict the output

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

``````C

Choices:
- Garbage Value
- 20
- Compiler Error


Question:
What is the output of following program?

# include <stdio.h>

int main()
{
   char str1[] = \"GeeksQuiz\";
   char str2[] = {\'G\', \'e\', \'e\', \'k\', \'s\', \'Q\', \'u\', \'i\', \'z\'};
   int n1 = sizeof(str1)/sizeof(str1[0]);
   int n2 = sizeof(str2)/sizeof(str2[0]);
   printf(\"n1 = %d, n2 = %d\", n1, n2);
   return 0;
}

``````C

Choices:
- n1 = 10, n2 = 9
- n1 = 10, n2 = 10
- n1 = 9, n2 = 9
- n1 = 9, n2 = 10


Question:
Predict the output?

#include <stdio.h>
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:
#include<stdio.h>
void fun(int arr[])
{
  int i;
  int arr_size = sizeof(arr)/sizeof(arr[0]);
  for (i = 0; i < arr_size; i++)
      printf(\"%d \", arr[i]);
}

int main()
{
  int i;
  int arr[4] = {10, 20 ,30, 40};
  fun(arr);
  return 0;
}

``````C

Choices:
- 10 20 30 40
- Machine Dependent
- 10 20
- Northing


Question:
int main()
{
 char *ptr = \"GeeksQuiz\";
 printf(\"%c", *&*&*ptr);
 return 0;
}

``````C

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


Question:
The Output of the following C code will be?

#include <stdio.h>

void my_toUpper(char* str, int index)
{
    *(str + index) &= ~32;
}

int main()
{
    char* arr = \"geeksquiz\";
    my_toUpper(arr, 0);
    my_toUpper(arr, 5);
    printf(\"%s\", arr);
    return 0;
}

``````C

Choices:
- GeeksQuiz
- geeksquiz
- Compiler dependent
- Runtime Error


Question:
Consider the following C program segment:

 char p[20];
 char *s = \"string\";
 int length = strlen(s);
 int i;
 for (i = 0; i < length; i++)
     p[i] = s[length — i];
 printf(\"%s\", p);

``````C

The output of the program is? (GATE CS 2004)

Choices:
- gnirts
- gnirt
- string
- no output is printed


Question:
Output?

int main()
{
    char a[2][3][3] = {\'g\',\'e\',\'e\',\'k\',\'s\',\'q\',\'u\',\'i\',\'z\'};
    printf(\"%s \", **a);
    return 0;
}

``````C

Choices:
- Compiler Error
- geeksquiz followed by garbage characters
- geeksquiz
- Runtime Error


Question:
#include<stdio.h>
int main()
{
    char str[] = \"GeeksQuiz\";
    printf(\"%s %s %s \", &str[5], &5[str], str+5);
    printf(\"%c %c %c \", *(str+6), str[6], 6[str]);
    return 0;
}

``````C

Choices:
- Runtime Error
- Compiler Error
- uiz uiz uiz u u u
- Quiz Quiz Quiz u u u


Question:
What is the output of following program?

#include<stdio.h>
void swap(char *str1, char *str2)
{
  char *temp = str1;
  str1 = str2;
  str2 = temp;
}

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

``````C

Choices:
- str1 is Quiz, str2 is Geeks
- str1 is Geeks, str2 is Quiz
- str1 is Geeks, str2 is Geeks
- str1 is Quiz, str2 is Quiz


Question:
#include<stdio.h>
int main()
{
   int a;
   char *x;
   x = (char *) &a;
   a = 512;
   x[0] = 1;
   x[1] = 2;
   printf(\"%d\\n\",a);
   return 0;
}

``````C

What is the output of above program?

Choices:
- Machine dependent
- 513
- 258
- Compiler Error


Question:
Assume that float takes 4 bytes, predict the output of following program.

#include <stdio.h>

int main()
{
    float arr[5] = {12.5, 10.0, 13.5, 90.5, 0.5};
    float *ptr1 = &arr[0];
    float *ptr2 = ptr1 + 3;

    printf(\"%f \", *ptr2);
    printf(\"%d\", ptr2 - ptr1);

   return 0;
}

``````C

Choices:
-
90.500000
3
-
90.500000
12
-
10.000000
12
-
0.500000
3


Question:
What does the following fragment of C-program print?

 char c[] = \"GATE2011\";
 char *p =c;
 printf(\"%s\", p + p[3] - p[1]) ;

``````C

Choices:
- GATE2011
- E2011
- 2011
- 011


Question:
Consider a compiler where int takes 4 bytes, char takes 1 byte and pointer takes 4 bytes.

#include <stdio.h>

int main()
{
    int arri[] = {1, 2 ,3};
    int *ptri = arri;

    char arrc[] = {1, 2 ,3};
    char *ptrc = arrc;

    printf(\"sizeof arri[] = %d \", sizeof(arri));
    printf(\"sizeof ptri = %d \", sizeof(ptri));

    printf(\"sizeof arrc[] = %d \", sizeof(arrc));
    printf(\"sizeof ptrc = %d \", sizeof(ptrc));

    return 0;
}

``````C

Choices:
-
sizeof arri[] = 3
sizeof ptri = 4
sizeof arrc[] = 3
sizeof ptrc = 4
-
sizeof arri[] = 12
sizeof ptri = 4
sizeof arrc[] = 3
sizeof ptrc = 1
-
sizeof arri[] = 3
sizeof ptri = 4
sizeof arrc[] = 3
sizeof ptrc = 1
-
sizeof arri[] = 12
sizeof ptri = 4
sizeof arrc[] = 3
sizeof ptrc = 4


Question:
Output of following program?

#include <stdio.h>

int main()
{
    int *ptr;
    int x;

    ptr = &x;
    *ptr = 0;

    printf(\" x = %d\\n\", x);
    printf(\" *ptr = %d\\n\", *ptr);

    *ptr += 5;
    printf(\" x  = %d\\n\", x);
    printf(\" *ptr = %d\\n\", *ptr);

    (*ptr)++;
    printf(\" x = %d\\n\", x);
    printf(\" *ptr = %d\\n\", *ptr);

    return 0;
}

``````C

Choices:
-
x = 0
 *ptr = 0
 x  = 5
 *ptr = 5
 x = 6
 *ptr = 6
-
x = garbage value
 *ptr = 0
 x  = garbage value
 *ptr = 5
 x = garbage value
 *ptr = 6
-
x = 0
 *ptr = 0
 x  = 5
 *ptr = 5
 x = garbage value
 *ptr = garbage value
-
x = 0
 *ptr = 0
 x  = 0
 *ptr = 0
 x = 0
 *ptr = 0


Question:
Output of following program?

# include <stdio.h>
void fun(int *ptr)
{
    *ptr = 30;
}

int main()
{
  int y = 20;
  fun(&y);
  printf(\"%d\", y);

  return 0;
}

``````C

Choices:
- 20
- 30
- Compiler Error
- Runtime Error


Question:
What is the output of following program?

# include <stdio.h>
void fun(int x)
{
    x = 30;
}

int main()
{
  int y = 20;
  fun(y);
  printf(\"%d\", y);
  return 0;
}

``````C

Choices:
- 30
- 20
- Compiler Error
- Runtime Error


Question:
#include<stdio.h>
int main()
{
    int arr[] = {10, 20, 30, 40, 50, 60};
    int *ptr1 = arr;
    int *ptr2 = arr + 5;
    printf(\"Number of elements between two pointer are: %d.\",
                                (ptr2 - ptr1));
    printf(\"Number of bytes between two pointers are: %d\",
                              (char*)ptr2 - (char*) ptr1);
    return 0;
}

``````C

Assume that an int variable takes 4 bytes and a char variable takes 1 byte

Choices:
-
Number of elements between two pointer are: 5.
Number of bytes between two pointers are: 20
-
Number of elements between two pointer are: 20.
Number of bytes between two pointers are: 20
-
Number of elements between two pointer are: 5.
Number of bytes between two pointers are: 5
- Compiler Error
- Runtime Error


Question:
Does C perform array out of bound checking? What is the output of the following program?

int main()
{
    int i;
    int arr[5] = {0};
    for (i = 0; i <= 5; i++)
        printf(\"%d \", arr[i]);
    return 0;
}

``````C

Choices:
- Compiler Error: Array index out of bound.
- The always prints 0 five times followed by garbage value
- The program always crashes.
- The program may print 0 five times followed by garbage value, or may crash if address (arr+5) is invalid.


Question:
Consider the following two C lines

int var1;
extern int var2;

``````C

Which of the following statements is correct

Choices:
- Both statements only declare variables, don\'t define them.
- First statement declares and defines var1, but second statement only declares var2
- Both statements declare define variables var1 and var2


Question:
In fopen(), the open mode "wx" is sometimes preferred "w" because.

1) Use of wx is more efficient.
2) If w is used, old contents of file are erased and a new empty file is created. When wx is used, fopen() returns NULL if file already exists.

Choices:
- Only 1
- Only 2
- Both 1 and 2
- Neither 1 nor 2


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 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:
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: 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:
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:
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: 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: 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: 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:
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:
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: Which of the following is not a storage class specifier in C?

Choices:
- auto
- register
- static
- extern
- 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: 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: In C, static storage class cannot be used with:

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


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:
Output of following program under the assumption that numbers are stored in 2\'s complement form.

#include<stdio.h>
int main()
{
   printf(\"%c\\n\", ~(\'C\' * -1));
   return 0;
}

``````C

Contributed by Sowmya.L.R

Choices:
- B
- A
- Compiler Error
- C


Question:
Pick the best statement for the below program:

#include \"stdio.h\"

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

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

 return 0;
}

``````C

Choices:
- Compile error because struct type (containing two fields i.e. an array of int and an int) has been specified along with the definition of array arr[] of this struct type.
- Compile error because of incorrect syntax for initialization of array arr[].
- No compile error and two elements of arr[] would be defined and initialized. Output would be “1 0 1 and 2 0 2”.
- No compile error and two elements of arr[] would be defined and initialized. Output would be “1 X 1 and 2 X 2” where X is some garbage random number.


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 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:
Suppose you are given an implementation of a queue of integers. The operations that can be performed on the queue are: i. isEmpty (Q) — returns true if the queue is empty, false otherwise. ii. delete (Q) — deletes the element at the front of the queue and returns its value. iii. insert (Q, i) — inserts the integer i at the rear of the queue. Consider the following function:

 void f (queue Q) {
int i ;
if (!isEmpty(Q)) {
   i = delete(Q);
   f(Q);
   insert(Q, i);
  }
}

``````C

What operation is performed by the above function f ?

Choices:
- Leaves the queue Q unchanged
- Reverses the order of the elements in the queue Q
- Deletes the element at the front of the queue Q and inserts it at the rear keeping the other elements in the same order
- Empties the queue Q


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:
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 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:
Consider the following C program:

   #include
           #define EOF -1
           void push (int); /* push the argument on the stack */
           int pop  (void); /* pop the top of the stack */
           void flagError ();
           int main ()
          {         int c, m, n, r;
                     while ((c = getchar ()) != EOF)
                    { if  (isdigit (c) )
                               push (c);
                     else if ((c == \'+\') || (c == \'*\'))
                    {          m = pop ();
                                n = pop ();
                                r = (c == \'+\') ? n + m : n*m;
                                push (r);
                      }
                      else if (c != \' \')
                               flagError ();
             }
              printf(\"% c\", pop ());
}

``````C

What is the output of the program for the following input ?
5 2 * 3 3 2 + * +

Choices:
- 15
- 25
- 30
- 150


Question:
Consider the following C code:

 int A[100][100];
 int main()
 {
    for(int i=1; i < 100 ; i++)
        for(int j=1; j < 100;j++)
            A[i][j] = (i/j)*(j/i);
   return 0;
 }

What will be the sum of the all the elements of double dimensional array A after implementing the above function ?

Choices:
- 100
- 99
- (100*99)/2
- 0


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:
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:
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:
Consider the program below in a hypothetical language which allows global variable and a choice of call by reference or call by value methods of parameter passing.

 int i ;
program main ()
{
    int j = 60;
    i = 50;
    call f (i, j);
    print i, j;
}
procedure f (x, y)
{
    i = 100;
    x = 10;
    y = y + i ;
}

``````C

Which one of the following options represents the correct output of the program for the two parameter passing mechanisms?

Choices:
- Call by value : i = 70, j = 10; Call by reference : i = 60, j = 70
- Call by value : i = 50, j = 60; Call by reference : i = 50, j = 70
- Call by value : i = 10, j = 70; Call by reference : i = 100, j = 60
- Call by value : i = 100, j = 60; Call by reference : i = 10, j = 70


Question:
The function f is defined as follows:

int f (int n) {
    if (n <= 1) return 1;
    else if (n % 2  ==  0) return f(n/2);
    else return f(3n - 1);
}

``````C

Assuming that arbitrarily large integers can be passed as a parameter to the function, consider the following statements.1. The function f terminates for finitely many different values of n ≥ 1. ii. The function f terminates for infinitely many different values of n ≥ 1. iii. The function f does not terminate for finitely many different values of n ≥ 1. iv. The function f does not terminate for infinitely many different values of n ≥ 1. Which one of the following options is true of the above?

Choices:
- (i) and (iii)
- (i) and (iv)
- (ii) and (iii)
- (ii) and (iv)


Question:
Consider the following C program:

#include <stdio.h>

int counter = 0;

int calc(int a, int b) {
  int c;

  counter++;
  if (b == 3)
    return (a * a * a);
  else {
    c = calc(a, b / 3);
    return (c * c * c);
  }
}

int main() {
  calc(4, 81);
  printf(\"%d\", counter);
}

``````C

The output of this program is ________ .

Note - This was Numerical Type question.

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


Question:
Pick the best statement for the below program:

#include <stdio.h>

int main()
{
    struct {
        int i;
        char c;
    } myVar = {.i = 100, .c = 'A'};

    printf("%d %c", myVar.i, myVar.c);

    return 0;
}

``````C

Choices:
- Compile error because struct type (containing two fields of dissimilar type i.e. an int and a char) has been mentioned along with definition of myVar of that struct type.
- Compile error because of incorrect syntax of initialization of myVar. Basically, member of operator (i.e. dot .) has been used without myVar.
- Compile error for not only B but for incorrect order of fields in myVar i.e. field c has been initialized first and then field i has been initialized.
- No compile error and it’ll print 100 A.


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:
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:
#include <stdio.h>

int main()
{
    unsigned int i = 65000;
    while (i++ != 0);
    printf(\"%d\", i);
    return 0;
}

``````C

Choices:
- Infinite Loop
- 0
- 1
- Run Time Error


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:
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: 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: 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:
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: 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: Which of the following is not a logical operator?


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: 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:
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()
{
    unsigned int i = 65000;
    while (i++ != 0);
    printf(\"%d\", i);
    return 0;
}

``````C

Choices:
- Infinite Loop
- 0
- 1
- Run Time Error


Question:
Consider the C program below.

#include <stdio.h>
int *A, stkTop;
int stkFunc (int opcode, int val)
{
    static int size=0, stkTop=0;
    switch (opcode)
    {
    case -1:
        size = val;
        break;
    case 0:
        if (stkTop < size ) A[stkTop++]=val;
        break;
    default:
        if (stkTop) return A[--stkTop];
    }
    return -1;
}
int main()
{
    int B[20];
    A=B;
    stkTop = -1;
    stkFunc (-1, 10);
    stkFunc (0, 5);
    stkFunc (0, 10);
    printf (\"%d\\n\", stkFunc(1, 0)+ stkFunc(1, 0));
}

``````C

The value printed by the above program is ___________

Choices:
- 9
- 10
- 15
- 17


Question:
Consider the following C declaration  struct (
short s[5];
union {
float y;
long z;
}u;
}t;
Assume that the objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment consideration, is

Choices:
- 22 bytes
- 18 bytes
- 14 bytes
- 10 bytes


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:
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:
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:
#include <stdio.h>
#if X == 3
    #define Y 3
#else
    #define Y 5
#endif

int main()
{
    printf(\"%d\", Y);
    return 0;
}

``````C

What is the output of the above program?

Choices:
- 3
- 5
- 3 or 5 depending on value of X
- Compile time error


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:
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: 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: The translator which performs macro calls expansion is called:

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


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:
Pick the best statement for the below program snippet:

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

``````C

Choices:
- No compile error and it’ll create array arr of 2 elements. Each of the element of arr contain a struct field of int array of 2 elements. arr[0]. a[0] would be 1 and arr[1].a[0] would be 2.
- No compile error and it’ll create array arr of 2 elements. Each of the element of arr contain a struct field of int array of 2 elements. arr[0]. a[0] would be 1 and arr[0].a[1] would be 2. The second element arr[1] would be ZERO i.e. arr[1].a[0] and arr[1].a[1] would be 0.
- No compile error and it’ll create array arr of 1 element. Each of the element of arr contain a struct field of int array of 2 elements. arr[0]. a[0] would be 1 and arr[0].a[1] would be 2.
- None of the above


Question: Which of the following operators can be applied on structure variables?

Choices:
- Equality comparison ( == )
- Assignment ( = )
- Both of the above
- None of the above


Question:
Consider the following C declaration

struct {
    short s[5];
    union {
         float y;
         long z;
    }u;
} t;

``````C

Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, is (GATE CS 2000)

Choices:
- 22 bytes
- 14 bytes
- 18 bytes
- 10 bytes


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

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


Question:
Pick the best statement for the below program:

#include <stdio.h>

int main()
{
    union {
        int i1;
        int i2;
    } myVar = {.i2 = 100};

    printf("%d %d", myVar.i1, myVar.i2);

    return 0;
}

``````C

Choices:
- Compile error due to incorrect syntax of initialization.
- No compile error and it’ll print “0 100”.
- No compile error and it’ll print “100 100”.


Question:
#include <stdio.h>

int main()
{
    unsigned int i = 65000;
    while (i++ != 0);
    printf(\"%d\", i);
    return 0;
}

``````C

Choices:
- Infinite Loop
- 0
- 1
- Run Time Error


Question:
Consider the code fragment written in JAVA below :

void f (int n)
{
  if (n <=1)  {
   System.out.print(n);
  }
  else {
   f (n/2);
   System.out.print(n%2);
  }
}

``````Java

What does f(173) print?

Choices:
- 010110101
- 010101101
- 10110101
- 10101101


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:
#include \"stdlib.h\"
int main()
{
 int *pInt;
 int **ppInt1;
 int **ppInt2;

 pInt = (int*)malloc(sizeof(int));
 ppInt1 = (int**)malloc(10*sizeof(int*));
 ppInt2 = (int**)malloc(10*sizeof(int*));

 free(pInt);
 free(ppInt1);
 free(*ppInt2);
 return 0;
}

``````C

Choose the correct statement w.r.t. above C program.

Choices:
- malloc() for ppInt1 and ppInt2 isn’t correct. It’ll give compile time error.
- free(*ppInt2) is not correct. It’ll give compile time error.
- free(*ppInt2) is not correct. It’ll give run time error.
- No issue with any of the malloc() and free() i.e. no compile/run time error.


Question:
#include \"stdio.h\"
int main()
{
 void *pVoid;
 pVoid = (void*)0;
 printf(\"%lu\",sizeof(pVoid));
 return 0;
}

``````C

Pick the best statement for the above C program snippet.

Choices:
- Assigning (void *)0 to pVoid isn’t correct because memory hasn’t been allocated. That’s why no compile error but it\'ll result in run time error.
- Assigning (void *)0 to pVoid isn’t correct because a hard coded value (here zero i.e. 0) can’t assigned to any pointer. That’s why it\'ll result in compile error.
- No compile issue and no run time issue. And the size of the void pointer i.e. pVoid would equal to size of int.
- sizeof() operator isn’t defined for a pointer of void type.


Question:
Consider the following variable declarations and definitions in C

i) int var_9 = 1;
ii) int 9_var = 2;
iii) int _ = 3;

``````C

Choose the correct statement w.r.t. above variables.

Choices:
- Both i) and iii) are valid.
- Only i) is valid.
- Both i) and ii) are valid.
- All are valid.


Question: Let x be an integer which can take a value of 0 or 1. The statement if(x = =0) x = 1; else x = 0; is equivalent to which one of the following?

Choices:
- x = 1 + x;
- x = 1 - x;
- x = x - 1;
- x = 1 % x;


Question: A program attempts to generate as many permutations as possible of the string, \'abcd\' by pushing the characters a, b, c, d in the same order onto a stack, but it may pop off the top character at any time. Which one of the following strings CANNOT be generated using this program?

Choices:
- abcd
- dcba
- cbad
- cabd


Question:
Consider following two C - program :

P1 :

int main()
{
    int (*ptr)(int ) = fun;
    (*ptr)(3);
    return 0;
}

int fun(int n)
{
  for(;n > 0; n--)
    printf(\"GeeksQuiz \");
  return 0;
}

``````C

P2 :

int main()
{
    void demo();
    void (*fun)();
    fun = demo;
    (*fun)();
    fun();
    return 0;
}

void demo()
{
    printf(\"GeeksQuiz \");
}

``````C

Which of the following option is correct?

Choices:
- P1 printed "GeeksQuiz  GeeksQuiz" and P2 printed "GeeksQuiz  GeeksQuiz"
- P1 printed "GeeksQuiz  GeeksQuiz" and P2 gives compiler error
- P1 gives compiler error and P2 printed "GeeksQuiz  GeeksQuiz"
- 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: In the context of C data types, which of the followings is correct?

Choices:
- “unsigned long long int” is a valid data type.
- “long long double” is a valid data type.
- “unsigned long double” is a valid data type.
- A), B) and C) all are valid data types.
- A), B) and C) all are invalid data types.


Question:
In the context of the following printf() in C, pick the best statement.

i) printf(\"%d\",8);
ii) printf(\"%d\",090);
iii) printf(\"%d\",00200);
iv) printf(\"%d\",0007000);

``````C

Choices:
- Only i) would compile. And it will print 8.
- Both i) and ii) would compile. i) will print 8 while ii) will print 90
- All i), ii), iii) and iv) would compile successfully and they will print 8, 90, 200 & 7000 respectively.
- Only i), iii) and iv) would compile successfully. They will print 8, 128 and 3584 respectively.


Question: Suppose a C program has floating constant 1.414, what\'s the best way to convert this as "float" data type?

Choices:
- (float)1.414
- float(1.414)
- 1.414f or 1.414F
- 1.414 itself of "float" data type i.e. nothing else required.


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:
In the context of the below program snippet, pick the best answer.

#include \"stdio.h\"
int arr[10][10][10];
int main()
{
 arr[5][5][5] = 123;
 return 0;
}

``````C

Which of the given printf statement(s) would be able to print arr[5][5][5]

(i) printf(\"%d\",arr[5][5][5]);
(ii) printf(\"%d\",*(*(*(arr+5)+5)+5));
(iii) printf(\"%d\",(*(*(arr+5)+5))[5]);
(iv) printf(\"%d\",*((*(arr+5))[5]+5));

``````C

Choices:
- only (i) would compile and print 123.
- both (i) and (ii) would compile and both would print 123.
- only (i), (ii) and (iii) would compile but only (i) and (ii) would print 123.
- only (i), (ii) and (iii) would compile and all three would print 123.
- all (i), (ii), (iii) and (iv) would compile but only (i) and (ii) would print 123.
- all (i), (ii), (iii) and (iv) would compile and all would print 123.


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:
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’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: 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: getc() returns EOF when

Choices:
- End of files is reached
- When getc() fails to read a character
- Both of the above
- None of the above


Question: When fopen() is not able to open a file, it returns

Choices:
- EOF
- NULL
- Runtime Error
- Compiler Dependent


Question: Which of the following true about FILE *fp

Choices:
- FILE is a keyword in C for representing files and fp is a variable of FILE type.
- FILE is a structure and fp is a pointer to the structure of FILE type
- FILE is a stream
- FILE is a buffered stream


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

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


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:
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:
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: 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: 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:
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:
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:
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:
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: As per C language standard, which of the followings is/are not keyword(s)? Pick the best statement. auto make main sizeof elseif

Choices:
- sizeof elseif make
- make main elseif
- make main
- auto make
- None of the above is keywords in C.


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:
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:
For the following “typedef” in C, pick the best statement

typedef int INT, *INTPTR, ONEDARR[10], TWODARR[10][10];

``````C

Choices:
- It will cause compile error because typedef is being used to define multiple aliases of incompatible types in the same statement.
- “INT x” would define x of type int. Remaining part of the statement would be ignored.
- “INT x” would define x of type int and “INTPTR y” would define pointer y of type int *. Remaining part of the statement would be ignored.
- “INT x” would define x of type int. “INTPTR y” would define pointer y of type int *. ONEDARR is an array of 10 int. TWODARR is a 2D array of 10 by 10 int.
- “INT x” would define x of type int. “INTPTR *y” would define pointer y of type int **. “ONEDARR  z” would define z as array of 10 int. “TWODARR t” would define t as array of 10 by 10 int.


Question: “typedef” in C basically works as an alias. Which of the following is correct for “typedef”?

Choices:
- typedef can be used to alias compound data types such as struct and union.
- typedef can be used to alias both compound data types and pointer to these compound types.
- typedef can be used to alias a function pointer.
- typedef can be used to alias an array.
- All of the above.


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:
The following function computes the value of  mCn correctly for all legal values m and n (m≥1,n≥0 and m>n)

 int func(int m, int n)
{
    if (E) return 1;
    else return(func(m -1, n) + func(m - 1, n - 1));
}

``````C

In the above function, which of the following is the correct expression for E?

Choices:
- (n = = 0) || (m = = 1)
- (n = = 0) && (m = = 1)
- (n = = 0) || (m = = n)
- (n = = 0) && (m = = n)


Question:
Which one of the choices given below would be printed when the following program is executed?

#include
void swap (int *x, int *y)
{
    static int *temp;
    temp = x;
    x = y;
    y = temp;
}
void printab ()
{
    static int i, a = -3, b = -6;
    i = 0;
    while (i <= 4)
    {
        if ((i++)%2 == 1) continue;
        a = a + i;
        b = b + i;
    }
    swap (&a, &b);
    printf(\"a =  %d, b = %d\\n\", a, b);
}
main()
{
    printab();
    printab();
}

``````C

Choices:
-
a = 0, b = 3
a = 0, b = 3
-
a = 3, b = 0
a = 12, b = 9
-
a = 3, b = 6
a = 3, b = 6
-
a = 6, b = 3
a = 15, b = 12


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

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 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:
Pick the best statement for the below program snippet:

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

``````C

Choices:
- No compile error and it’ll create array arr of 2 elements. Each of the element of arr contain a struct field of int array of 2 elements. arr[0]. a[0] would be 1 and arr[1].a[0] would be 2.
- No compile error and it’ll create array arr of 2 elements. Each of the element of arr contain a struct field of int array of 2 elements. arr[0]. a[0] would be 1 and arr[0].a[1] would be 2. The second element arr[1] would be ZERO i.e. arr[1].a[0] and arr[1].a[1] would be 0.
- No compile error and it’ll create array arr of 1 element. Each of the element of arr contain a struct field of int array of 2 elements. arr[0]. a[0] would be 1 and arr[0].a[1] would be 2.
- None of the above


Question:
Consider the code fragment written in C below :

void f (int n)
{
    if (n <= 1)  {
        printf (\"%d\", n);
    }
    else {
        f (n/2);
        printf (\"%d\", n%2);
    }
}

``````C

Which of the following implementations will produce the same output for f(173) as the above code? P1

void f (int n)
{
    if (n/2)  {
        f(n/2);
    }
    printf (\"%d\", n%2);
}

``````C

P2

void f (int n)
{
    if (n <=1)  {
        printf (\"%d\", n);
    }
    else {
        printf (\"%d\", n%2);
        f (n/2);
    }
}

``````C

Choices:
- Both P1 and P2
- P2 only
- P1 only
- Neither P1 nor P2


Question:
Consider the following C program:

#include <stdio.h>
typedef struct
{
    char *a;
    char *b;
} t;
void f1(t s);
void f2(t *p);
main()
{
    static t s = {\"A\", \"B\"};
    printf (\"%s %s\\n\", s.a, s.b);
    f1(s);
    printf (\"%s %s\\n\", s.a, s.b);
    f2(&s);
}
void f1(t s)
{
    s.a = \"U\";
    s.b = \"V\";
    printf (\"%s %s\\n\", s.a, s.b);
    return;
}
void f2(t *p)
{
    p -> a  = \"V\";
    p -> b = \"W\";
    printf(\"%s %s\\n\", p -> a, p -> b);
    return;
}

``````C

What is the output generated by the program ?

Choices:
-
A B
U V
V W
V W
-
A B
U V
A B
V W
-
A B
U V
U V
V W
-
A B
U V
V W
U V


Question: fseek() should be preferred over rewind() mainly because

Choices:
- rewind() doesn\'t work for empty files
- rewind() may fail for large files
- In rewind, there is no way to check if the operations completed successfully
- All of the above


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:
Find out the correct statement for the following program.

#include \"stdio.h\"

typedef int (*funPtr)(int);

int inc(int a)
{
 printf(\"Inside inc() %d\\n\",a);
 return (a+1);
}

int main()
{

 funPtr incPtr1 = NULL, incPtr2 = NULL;

 incPtr1 = &inc; /* (1) */
 incPtr2 = inc; /* (2) */

 (*incPtr1)(5); /* (3) */
 incPtr2(5); /* (4)*/

 return 0;
}

``````C

Choices:
- Line with comment (1) will give compile error.
- Line with comment (2) will give compile error.
- Lines with (1) & (3) will give compile error.
- Lines with (2) & (4) will give compile error.
- No compile error and program will run without any issue.


Question:
In a C program, following variables are defined:

 float      x = 2.17;
 double   y = 2.17;
 long double z = 2.17;

``````C

Which of the following is correct way for printing these variables via printf.

Choices:
- printf("%f %lf %Lf",x,y,z);
- printf(“%f %f %f”,x,y,z);
- printf("%f %ff %fff",x,y,z);
- printf("%f %lf %llf",x,y,z);


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:
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:
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:
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:
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: 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:
In a C program snippet, followings are used for definition of Integer variables?

  signed s;
  unsigned u;
  long l;
  long long ll;

``````C

Pick the best statement for these.

Choices:
- All of the above variable definitions are incorrect because basic data type int is missing.
- All of the above variable definitions are correct because int is implicitly assumed in all of these.
- Only “long l;” and “long long ll;” are valid definitions of variables.
- Only “unsigned u;” is valid definition of variable.


Question: Which of the followings is correct for a function definition along with storage-class specifier in C language?

Choices:
- int fun(auto int arg)
- int fun(static int arg)
- int fun(register int arg)
- int fun(extern int arg)
- All of the above are correct.


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:
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:
Find out the correct statement for the following program.

#include \"stdio.h\"

int * gPtr;

int main()
{
 int * lPtr = NULL;

 if(gPtr == lPtr)
 {
   printf(\"Equal!\");
 }
 else
 {
  printf(\"Not Equal\");
 }

 return 0;
}

``````C

Choices:
- It’ll always print Equal.
- It’ll always print Not Equal.
- Since gPtr isn’t initialized in the program, it’ll print sometimes Equal and at other times Not Equal.


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:
Consider the following C-program:

double foo (double); /* Line 1 */

int main()
{

    double da, db;

    // input da

    db = foo(da);

}

double foo(double a)
{
    return a;
}

``````C

The above code compiled without any error or warning. If Line 1 is deleted, the above code will show:

Choices:
- no compile warning or error
- some compiler-warnings not leading to unintended results
- some compiler-warnings due to type-mismatch eventually leading to unintended results
- compiler errors


Question:
Choose the correct option to fill the ?1 and ?2 so that the program prints an input string in reverse order. Assume that the input string is terminated by a new line character.
#include <stdio.h>
void wrt_it (void);
int main (void)
{
    printf("Enter Text");
    printf ("\\n");
    wrt_ it();
    printf ("\\n");
    return 0;
}
void wrt_it (void)
{
    int c;
    if (?1)
        wrt_it();
    ?2
}

Choices:
-
?1 is  getchar() ! = \'\\n\'
?2 is  getchar(c);
-
?1 is  (c = getchar()); ! = \'\\n\'
?2 is  getchar(c);
-
?1 is  c! = \'\\n\'
?2 is  putchar(c);
-
?1 is  (c = getchar()) ! = \'\\n\'
?2 is  putchar(c);


Question:
The value of j at the end of the execution of the following C program.

int incr(int i)
{
   static int count = 0;
   count = count + i;
   return (count);
}
main()
{
   int i,j;
   for (i = 0; i <=4; i++)
      j = incr(i);
}

``````C

Choices:
- 10
- 4
- 6
- 7


Question:
Pick the best statement for the below program:

#include \"stdio.h\"

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

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

 return 0;
}

``````C

Choices:
- Compile error because struct type (containing two fields i.e. an array of int and an int) has been specified along with the definition of array arr[] of this struct type.
- Compile error because of incorrect syntax for initialization of array arr[].
- No compile error and two elements of arr[] would be defined and initialized. Output would be “1 0 1 and 2 0 2”.
- No compile error and two elements of arr[] would be defined and initialized. Output would be “1 X 1 and 2 X 2” where X is some garbage random number.


Question:
Pick the best statement for the below program:

#include <stdio.h>

int main()
{
    struct {
        int i;
        char c;
    } myVar = {.i = 100, .c = 'A'};

    printf("%d %c", myVar.i, myVar.c);

    return 0;
}

``````C

Choices:
- Compile error because struct type (containing two fields of dissimilar type i.e. an int and a char) has been mentioned along with definition of myVar of that struct type.
- Compile error because of incorrect syntax of initialization of myVar. Basically, member of operator (i.e. dot .) has been used without myVar.
- Compile error for not only B but for incorrect order of fields in myVar i.e. field c has been initialized first and then field i has been initialized.
- No compile error and it’ll print 100 A.


Question:
Pick the best statement for the below program:

#include <stdio.h>

int main()
{
    union {
        int i1;
        int i2;
    } myVar = {.i2 = 100};

    printf("%d %d", myVar.i1, myVar.i2);

    return 0;
}

``````C

Choices:
- Compile error due to incorrect syntax of initialization.
- No compile error and it’ll print “0 100”.
- No compile error and it’ll print “100 100”.


Question:
Consider the following declaration :struct addr {
     char city[10];
     char street[30];
     int pin ;
};

struct {
char name[30];
int gender;
struct addr locate;
} person , *kd = &person ;
Then *(kd -> name +2) can be used instead of

Choices:
- person.name +2
- kd -> (name +2 )
- *((*kd).name + 2 )
- either (A) or (B), but not (C)


Question:
Consider the following C declaration  struct (
short s[5];
union {
float y;
long z;
}u;
}t;
Assume that the objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment consideration, is

Choices:
- 22 bytes
- 18 bytes
- 14 bytes
- 10 bytes


Question:
Consider the following C declaration

struct {
    short s[5];
    union {
         float y;
         long z;
    }u;
} t;

``````C

Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, is (GATE CS 2000)

Choices:
- 22 bytes
- 14 bytes
- 18 bytes
- 10 bytes


Question: Which of the following operators can be applied on structure variables?

Choices:
- Equality comparison ( == )
- Assignment ( = )
- Both of the above
- None of the above


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

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

``````C

Choices:
- No compile error and it’ll create array arr of 2 elements. Each of the element of arr contain a struct field of int array of 2 elements. arr[0]. a[0] would be 1 and arr[1].a[0] would be 2.
- No compile error and it’ll create array arr of 2 elements. Each of the element of arr contain a struct field of int array of 2 elements. arr[0]. a[0] would be 1 and arr[0].a[1] would be 2. The second element arr[1] would be ZERO i.e. arr[1].a[0] and arr[1].a[1] would be 0.
- No compile error and it’ll create array arr of 1 element. Each of the element of arr contain a struct field of int array of 2 elements. arr[0]. a[0] would be 1 and arr[0].a[1] would be 2.
- None of the above


Question:
#include <stdio.h>
#if X == 3
    #define Y 3
#else
    #define Y 5
#endif

int main()
{
    printf(\"%d\", Y);
    return 0;
}

``````C

What is the output of the above program?

Choices:
- 3
- 5
- 3 or 5 depending on value of X
- Compile time error


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

``````C

Choices:
- 3 6
- Compiler Dependent
- 3 4
- 3 3


Question:
Predict the output of following program. Assume that the characters are represented using ASCII Values.

#include <stdio.h>
#define VAL 32

int main()
{
    char arr[] = \"geeksquiz\";
    *(arr + 0) &= ~VAL;
    *(arr + 5) &= ~VAL;
    printf(\"%s\", arr);

    return 0;
}

``````C

Choices:
- GeeksQuiz
- geeksQuiz
- Geeksquiz
- geeksquiz
- Garbage eeks Garbage uiz


Question:
Predict the output of the below program:

#include <stdio.h>
int main()
{
    printf(\"%d\", 1 << 2 + 3 << 4);
    return 0;
}

``````C

Choices:
- 112
- 52
- 512
- 0


Question: Which of the following can have different meaning in different contexts?

Choices:
- Both of the above
- There are no such operators in C


Question: In C, two integers can be swapped using minimum

Choices:
- 0 extra variable
- 1 extra variable
- 2 extra variable
- 4 extra variable


Question:
What does the following statement do?

 x  = x | 1 << n;

``````C

Choices:
- Sets x as 2n
- Sets (n+1)th bit of x
- Toggles (n+1)th bit of x
- Unsets (n+1)th bit of x


Question:
Predict the output of following C program

#include <stdio.h>
int main()
{
    int i = 0;
    do
    {
        printf(\"GeeqsQuiz \");
        i = i++;
    }
    while (i < 5);
    return 0;
}

``````C

Choices:
- GeeqsQuiz GeeqsQuiz GeeqsQuiz GeeqsQuiz GeeqsQuiz
- Infinite time GeeksQuiz
- Undefined Behavior
- None of the above


Question:
Assume that the size of an integer is 4 bytes, predict the output of following program.

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

``````C

Choices:
- 12 4
- 13 4
- Compiler Error
- 0 4


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

``````C

Choices:
- Infinite Loop
- 99 99 99
- 99 98 97
- 2 2 2


Question:
How many times GeeksQuiz is printed

#include<stdio.h>
int main()
{
    int i = -5;
    while (i <= 5)
    {
        if (i >= 0)
            break;
        else
        {
            i++;
            continue;
        }
        printf(\"GeeksQuiz\");
    }
    return 0;
}

``````C

Choices:
- 10 times
- 5 times
- Infinite times
- 0 times