Online C Programming Test - C Programming Test - Random
- 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
Test Review : View answers and explanation for this test.
#include<stdio.h>
int main()
{
int i = 0;
i++;
if(i <= 5)
{
printf("IndiaBIX\n");
exit(0);
main();
}
return 0;
}
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".
#include<stdio.h>
int main()
{
float a;
scanf("%f", &a);
printf("%f\n", a+a+a);
printf("%f\n", 3*a);
return 0;
}
#include<stdio.h>
int fun(int(*)());
int main()
{
fun(main);
printf("Hi\n");
return 0;
}
int fun(int (*p)())
{
printf("Hello ");
return 0;
}
| 1: | #ifdef |
| 2: | #if |
| 3: | #elif |
| 4: | #undef |
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.
#include<stdio.h>
#define X (4+Y)
#define Y (X+3)
int main()
{
printf("%d\n", 4*X+2);
return 0;
}
#include<stdio.h>
#include<string.h>
int main()
{
printf("%d\n", strlen("123456"));
return 0;
}
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".
#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;
}
#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;
}
#include<stdio.h>
int main()
{
struct bits
{
int i:40;
}bit;
printf("%d\n", sizeof(bit));
return 0;
}
#include<stdio.h>
int main()
{
int n=5;
printf("n=%*d\n", n, n);
return 0;
}
It prints n= 5
#include<stdio.h>
int main()
{
unsigned int m = 32;
printf("%x\n", ~m);
return 0;
}
#include<stdio.h>
int main()
{
const int k=7;
int *const q=&k;
printf("%d", *q);
return 0;
}
#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;
}