Online C Programming Test - C Programming Test - Random

Instruction:

  • This is a FREE online test. Beware of scammers who ask for money to attend this test.
  • Total number of questions: 20.
  • Time allotted: 30 minutes.
  • Each question carries 1 mark; there are no negative marks.
  • DO NOT refresh the page.
  • All the best!

Marks : 2/20


Total number of questions
20
Number of answered questions
0
Number of unanswered questions
20
Test Review : View answers and explanation for this test.

1.
Which of the following statements are correct about the below program?
#include<stdio.h>
int main()
{
    int i = 0;
    i++;
    if(i <= 5)
    {
        printf("IndiaBIX\n");
        exit(0);
        main();
    }
    return 0;
}
The program prints 'IndiaBIX' 5 times
The program prints 'IndiaBIX' one time
The call to main() after exit() doesn't materialize.
The compiler reports an error since main() cannot call itself.
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

Step 1: int i = 0; here variable i is declared as an integer type and initialized to '0'(zero).
Step 2: i++; here variable i is increemented by 1(one). Hence, i = 1
Step 3: if(i <= 5) becomes if(1 <= 5) here we are checking '1' is less than or equal to '5'. Hence the if condition is satisfied.
Step 4: printf("IndiaBIX\n"); It prints "IndiaBIX"
Step 5: exit(); terminates the program execution.

Hence the output is "IndiaBIX".


2.
Will the printf() statement print the same values for any values of a?
#include<stdio.h>
int main()
{
    float a;
    scanf("%f", &a);
    printf("%f\n", a+a+a);
    printf("%f\n", 3*a);
    return 0;
}
Yes
No
Your Answer: Option
(Not Answered)
Correct Answer: Option

3.
What will be the output of the program?
#include<stdio.h>
int fun(int(*)());

int main()
{
    fun(main);
    printf("Hi\n");
    return 0;
}
int fun(int (*p)())
{
    printf("Hello ");
    return 0;
}
Infinite loop
Hi
Hello Hi
Error
Your Answer: Option
(Not Answered)
Correct Answer: Option

4.
Which of the following are correct preprocessor directives in C?
1: #ifdef
2: #if
3: #elif
4: #undef
1, 2
4
1, 2, 4
1, 2, 3, 4
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

The macros #ifdef #if #elif are called conditional macros.

The macro #undef undefine the previosly declared macro symbol.

Hence all the given statements are macro preprocessor directives.


5.
Will the program compile successfully?
#include<stdio.h>
#define X (4+Y)
#define Y (X+3)

int main()
{
    printf("%d\n", 4*X+2);
    return 0;
}
Yes
No
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:
Reports an error: Undefined symbol 'X'

6.
What is (void*)0?
Representation of NULL pointer
Representation of void pointer
Error
None of above
Your Answer: Option
(Not Answered)
Correct Answer: Option

7.
Are the three declarations char **apple, char *apple[], and char apple[][] same?
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option

8.
What will be the output of the program ?
#include<stdio.h>
#include<string.h>

int main()
{
    printf("%d\n", strlen("123456"));
    return 0;
}
6
12
7
2
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

The function strlen returns the number of characters in the given string.

Therefore, strlen("123456") returns 6.

Hence the output of the program is "6".


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

    struct course
    {
        int courseno;
        char coursename[25];
    };
int main()
{
    struct course c[] = { {102, "Java"}, 
                          {103, "PHP"}, 
                          {104, "DotNet"}     };

    printf("%d ", c[1].courseno);
    printf("%s\n", (*(c+2)).coursename);
    return 0;
}
103 DotNet
102 Java
103 PHP
104 DotNet
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

int main()
{
    int i=4, j=8;
    printf("%d, %d, %d\n", i|j&j|i, i|j&j|i, i^j);
    return 0;
}
12, 12, 12
112, 1, 12
32, 1, 12
-64, 1, 12
Your Answer: Option
(Not Answered)
Correct Answer: Option

11.
Point out the error in the program in 16-bit platform?
#include<stdio.h>

int main()
{
    struct bits
    {
        int i:40;
    }bit;

    printf("%d\n", sizeof(bit));
    return 0;
}
4
2
Error: Bit field too large
Error: Invalid member access in structure
Your Answer: Option
(Not Answered)
Correct Answer: Option

12.
one of elements of a structure can be a pointer to the same structure.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option

13.
size of union is size of the longest element in the union
Yes
No
Your Answer: Option
(Not Answered)
Correct Answer: Option

14.
Will the following program work?
#include<stdio.h>

int main()
{
    int n=5;
    printf("n=%*d\n", n, n);
    return 0;
}
Yes
No
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:
It prints n=    5

15.
If an unsigned int is 2 bytes wide then, What will be the output of the program ?
#include<stdio.h>

int main()
{
    unsigned int m = 32;
    printf("%x\n", ~m);
    return 0;
}
ffff
0000
ffdf
ddfd
Your Answer: Option
(Not Answered)
Correct Answer: Option

16.
Bitwise can be used to generate a random number.
Yes
No
Your Answer: Option
(Not Answered)
Correct Answer: Option

17.
Point out the error in the program.
#include<stdio.h>

int main()
{
    const int k=7;
    int *const q=&k;
    printf("%d", *q);
    return 0;
}
Error: RValue required
Error: Lvalue required
Error: cannot convert from 'const int *' to 'int *const'
No error
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:
No error. This will produce 7 as output.

18.
Point out the correct statement which correctly allocates memory dynamically for 2D array following program?
#include<stdio.h>
#include<stdlib.h>

int main()
{
    int *p, i, j;
    /* Add statement here */
    for(i=0; i<3; i++)
    {
        for(j=0; j<4; j++)
        {
            p[i*4+j] = i;
            printf("%d", p[i*4+j]);
        }
    }
    return 0;
}
p = (int*) malloc(3, 4);
p = (int*) malloc(3*sizeof(int));
p = malloc(3*4*sizeof(int));
p = (int*) malloc(3*4*sizeof(int));
Your Answer: Option
(Not Answered)
Correct Answer: Option

19.
Can we pass a variable argument list to a function at run-time?
Yes
No
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:
Every actual argument list must be known at compile time. In that sense it is not truly a variable argument list.

20.
While defining a variable argument list function we drop the ellipsis(...)?
Yes
No
Your Answer: Option
(Not Answered)
Correct Answer: Option

*** END OF THE TEST ***
Time Left: 00:29:56
Post your test result / feedback here: