Welcome to C Programming Quiz, Randomly Selected !!

Question 1. what is the output of the following code sample?
#include <stdio.h>
int i; 
void increment( int i ) 
{ 
   i++  ; 
} 

int main() 
{ 
   for( i = 0; i < 10; increment( i ) ) 
   { 
   } 
   printf("i=%d\n", i); 
   return 0; 
}

it wont compile at all

i=9

i=10

wont print anything

Question 2. The function below has a flaw that may result in a serious error during some invocations. Which one of the following describes the deficiency illustrated above?
int fibonacci (int n)
{ 
 switch (n)
 { 
  default: 
      return (fibonacci(n - 1) +  fibonacci(n - 2)); 
  case 1: 
  case 2: 
 } 
  return 1; 
}

For some values of n, the environment will almost certainly exhaust its stack space before the calculation completes.

An error in the algorithm causes unbounded recursion for all values of n.

A break statement should be inserted after each case. Fall-through is not desirable here.

Since the default case is given first, it will be executed before any case matching n.

Question 3. What does y in the sample code evaluated to?
int x[] = { 1, 4, 8, 5, 1, 4 }; 
int *ptr, y; 
ptr  = x +  4; 
y = ptr - x;

-3

4

4 + sizeof( int )

0

Question 4. What would be the equivalent pointer expression for referring the array element a[i][j][k][l]

((((a+i)+j)+k)+l)

*(*(*(*(a+i)+j)+k)+l)

(((a+i)+j)+k+l)

((a+i)+j+k+l)

Question 5. what will be the output of the following program
#include<stdio.h>
#include<stdarg.h>
void fun(char *msg, ...);

int main()
{
    fun("TechInfoGurus", 1, 4, 7, 11, 0);
    return 0;
}
void fun(char *msg, ...)
{
    va_list ptr;
    int num;
    va_start(ptr, msg);
    num = va_arg(ptr, int);
    num = va_arg(ptr, int);
    printf("%d", num);
}

TechInfoGurus 1 7 11 0

1

4

7

Question 6. We want to round off x, a float, to an int value, The correct way to do is

y = (int)(x + 0.5)

y = int(x + 0.5)

y = (int)x + 0.5

y = (int)((int)x + 0.5)

Question 7. What does the following declaration mean?
int (*ptr)[10]

ptr is array of pointers to 10 integers

ptr is a pointer to an array of 10 integers

ptr is an array of 10 integers

ptr is an pointer to array

Question 8. what is the output of the following code sample
int main(void) {
                char *p="abc";
                char *q="abc123";
                while(*p=*q)
                {
                                print("%c %c",*p,*q);
                }
}

aabbcc123

abcabc123

infinite loop

segmentation fault

Question 9. What will the function rewind() do?

Reposition the file pointer to a character reverse.

Reposition the file pointer stream to end of file.

Reposition the file pointer to begining of that line.

Reposition the file pointer to begining of file.

Question 10. what is the output of the following code sample?
int x = 0; 
for (x=1; x<4; x++); 
printf("x=%d\n", x);

x=0

x=4

x=5

no output, it will loop forever