Welcome to C Programming Quiz, Randomly Selected !!

Question 1. Which of the following cannot be checked in a switch-case statement?

character

integer

float

enum

Question 2. What will be the output of the program?
#include<stdio.h>

int main()
{
    const int x=5;
    const int *ptrx;
    ptrx = &x;
    *ptrx = 10;
    printf("%d\n", x);
    return 0;
}

5

10

error

garbage value

Question 3. The following program releases memory from a link list..which of the following is true?
struct node *nPtr, *sPtr;    /* pointers for a linked list. */ 
for (nPtr=sPtr; nPtr; nPtr=nPtr->next)
{    
    free(nPtr);
}

It will work correctly since the for loop covers the entire list.

It may fail since each node "nPtr" is freed before its next address can be accessed.

In the for loop, the assignment "nPtr=nPtr->next" should be changed to "nPtr=nPtr.next".

The loop will never end.

Question 4. what is the output of the following program
#include "stdio.h"
int f(int *a, int n)
{
    if (n <= 0) return 0;
    else if (*a % 2 == 0) return *a +  f(a + 1, n-1);
    else return *a - f(a + 1, n-1);
}

int main()
{
    int a[] = {12, 7, 13, 4, 11, 6};
    printf("%d", f(a, 6));
    return 0;
}

-9

5

15

19

Question 5. What can be the missing statement for the code to work properly?
int main(void) {
                array x={1,2,3,4,5};
                printf("%d", x[2]);
                return 0;
}

#define array int[]

#define array int*

typedef array int[]

typedef array int*

Question 6. 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 7. What are the different types of real data type in C ?

float, double

short int, double, long int

float, double, long double

double, long int, float

Question 8. What does x mean in this code sample ?
typedef char (*(*arrfptr[3])())[10];
arrfptr x;

x is a pointer

x is an array of three pointer

x is an array of three function pointers

error in declaration of x

Question 9. A pointer is a

keyword used to create variables

variable that stores address of an instruction

variable that stores address of other variable

all of the above

Question 10. The function crash(), defined below, triggers a fault in the memory management hardware for many architectures. Which one of the following explains why "got here" may NOT be printed before the crash?
void crash (void) 
{ 
 printf("got here"); 
 *((char *) 0) = 0; 
}

The C standard says that dereferencing a null pointer causes undefined behavior. This may explain why printf() apparently fails.

printf() always buffers output until a newline character appears in the buffer. Since no newline was present in the format string, nothing is printed.

If the standard output stream is buffered, the library buffers may not be flushed before the crash occurs.

printf() expects more than a single argument. Since only one argument is given, the crash may actually occur inside printf(), which explains why the string is not printed. puts() should be used instead.