Welcome to C Programming Quiz, Intermediate Level !!

Question 1. char txt [20] = "Hello world!\0";
How many bytes are allocated by the definition above?

11 bytes

12 bytes

13 bytes

20 bytes

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

union employee
{
    char name[15];
    int age;
    float salary;
};
const union employee e1;

int main()
{
    strcpy(e1.name, "K");
    printf("%s %d %f", e1.name, e1.age, e1.salary);
    return 0;
}

Error: RValue required

Error: cannot convert from 'const int *' to 'int *const'

Error: LValue required in strcpy

no error

Question 3. 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 4. What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array?

The element will be set to 0.

The compiler would report an error.

The program may crash if some important data gets overwritten.

The array size would appropriately grow.

Question 5. 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

Question 6. what will be the output of the following program?
int a=10,b;
b=a++ + ++a;
printf("%d,%d,%d,%d",b,a++,a,++a);

12,10,11,13

22,10,11,13

12,11,11,11

Undefined Behavior

Question 7. what will be the value of "counter" after the following code is executed?
x = 3, counter = 0; 
while ((x-1)) 
{ 
   ++counter; 
   x--; 
}

0

1

2

3

Question 8. 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 9. How many times the program will print "TechInfoGurus" ?
#include<stdio.h>

int main()
{
    printf("TechInfoGurus");
    main();
    return 0;
}

infinite number of times

ERROR : main() cant be called recursively

65535 times

Till stack doesn't overflow

Question 10.
long factorial (long x) 
{ 
 ???? 
 return x * factorial(x - 1); 
}

With what do you replace the ???? to make the function shown above return the correct answer?

if (x == 0) return 0;

if (x <= 1) return 1;

if (x >= 2) return 2;

if (x == 0) return 1;