Online C Programming Test - C Programming Test 9
- This is a FREE online test. Beware of scammers who ask for money to attend this test.
- Total number of questions: 20.
- Time allotted: 20 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 x=1, y=1;
for(; y; printf("%d %d\n", x, y))
{
y = x++ <= 5;
}
printf("\n");
return 0;
}
z = x + y * z / 4 % 2 - 1
The range of long double is 3.4E-4932 to 1.1E+4932
#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>
#include<stdlib.h>
int main()
{
int i=0;
i++;
if(i<=5)
{
printf("IndiaBIX");
exit(1);
main();
}
return 0;
}
Step 1: int i=0; The variable i is declared as in integer type and initialized to '0'(zero).
Step 2: i++; Here variable i is increemented by 1. Hence i becomes '1'(one).
Step 3: if(i<=5) becomes if(1 <=5). Hence the if condition is satisfied and it enter into if block statements.
Step 4: printf("IndiaBIX"); It prints "IndiaBIX".
Step 5: exit(1); This exit statement terminates the program execution.
Hence the output is "IndiaBIx".
#include<stdio.h>
int main()
{
int i, a[] = {2, 4, 6, 8, 10};
change(a, 5);
for(i=0; i<=4; i++)
printf("%d, ", a[i]);
return 0;
}
void change(int *b, int n)
{
int i;
for(i=0; i<n; i++)
*(b+1) = *(b+i)+5;
}
#include<stdio.h>
int main()
{
int arr[]={2, 3, 4, 1, 6};
printf("%u, %u, %u\n", arr, &arr[0], &arr);
return 0;
}
Step 1: int arr[]={2, 3, 4, 1, 6}; The variable arr is declared as an integer array and initialized.
Step 2: printf("%u, %u, %u\n", arr, &arr[0], &arr); Here,
The base address of the array is 1200.
=> arr, &arr is pointing to the base address of the array arr.
=> &arr[0] is pointing to the address of the first element array arr. (ie. base address)
Hence the output of the program is 1200, 1200, 1200
#include<stdio.h>
int main()
{
int a[3][4];
fun(a);
return 0;
}
void fun(int p[][4]){ } is the correct way to write the function fun(). while the others are considered only the function fun() is called by using call by reference.
#include<stdio.h>
int main()
{
printf(5+"IndiaBIX\n");
return 0;
}
printf(5+"IndiaBIX\n"); In the printf statement, it skips the first 5 characters and it prints "BIX"
#include<stdio.h>
int main()
{
enum status {pass, fail, absent};
enum status stud1, stud2, stud3;
stud1 = pass;
stud2 = absent;
stud3 = fail;
printf("%d %d %d\n", stud1, stud2, stud3);
return 0;
}
struct emp
{
int ecode;
struct emp e;
};
#include<stdio.h>
int main()
{
FILE *ptr;
char i;
ptr = fopen("myfile.c", "r");
while((i=fgetc(ptr))!=NULL)
printf("%c", i);
return 0;
}
The %s format specifier tells the compiler the given input was string of characters.
#include<stdio.h>
char *fun(unsigned int num, int base);
int main()
{
char *s;
s=fun(128, 2);
s=fun(128, 16);
printf("%s\n",s);
return 0;
}
char *fun(unsigned int num, int base)
{
static char buff[33];
char *ptr = &buff[sizeof(buff)-1];
*ptr = '\0';
do
{
*--ptr = "0123456789abcdef"[num %base];
num /=base;
}while(num!=0);
return ptr;
}
#include<stdio.h>
int main()
{
const c = -11;
const int d = 34;
printf("%d, %d\n", c, d);
return 0;
}
Step 1: const c = -11; The constant variable 'c' is declared and initialized to value "-11".
Step 2: const int d = 34; The constant variable 'd' is declared as an integer and initialized to value '34'.
Step 3: printf("%d, %d\n", c, d); The value of the variable 'c' and 'd' are printed.
Hence the output of the program is -11, 34
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i, j;
int(*p)[3];
p = (int(*)[3])malloc(3*sizeof(*p));
return 0;
}
char *arr[10];
#include<stdio.h>
int main()
{
char str[] = "IndiaBIX";
printf("%.#s %2s", str, str);
return 0;
}
#include<stdio.h>
#include<string.h>
int main()
{
char str1[] = "Learn through IndiaBIX\0.com", str2[120];
char *p;
p = (char*) memccpy(str2, str1, 'i', strlen(str1));
*p = '\0';
printf("%s", str2);
return 0;
}
Declaration:
void *memccpy(void *dest, const void *src, int c, size_t n); : Copies a block of n bytes from src to dest
With memccpy(), the copying stops as soon as either of the following occurs:
=> the character 'i' is first copied into str2
=> n bytes have been copied into str2