C Language Online Test 3

C Language Online Test 3

C Langauge Practice Programs-MCQs-Objective-Questionswhat is the output?

int main()
{
int a[100];
int sum = 0;
int k;
for(k=0; k<100; k++)
{
*(a+k) = k;
}
printf(“%d”,a[–k]);
return 0;
}

Ans: 99


What is the output?

void main()
{
int i=5;
int *p;
p = &i;
printf(”The value of i is : %d \n”,*p);
*p = *p + 10;
printf(”The value of i is : %d \n”, *p);
}

A: 5 15


What is the output?

void main()
{
int a = 5;
double b = 3.1415;
void *vp;
vp = &a;
printf(“a=%d\n”, *((int *)vp));
vp=&b;
printf(“b=%lf\n”,*((double *)vp));
}

Ans: 5     3.1415


What is the output?

int main ()
{
int *p;
p = NULL;
printf(“ \n The value of p is %d \n” , p);
return 0;
}

Ans: 0


What is the output?

void main()
{
// Local Declarations
int a=5;
int *p;
int **q;
int ***r;
// Statements
p = &a;
q = &p;
r = &q;
printf(“%d %d %d”, *p, **q, ***r);
}

Ans; 5     5    5


Attend Free Demo and Learn   C LANGUAGE ONLINE TRAINING   by Real-Time Expert


What is the output?

#include <stdio.h>
void main()
{
int a[] = {10,12,6,7,2};
int i,sum=0;
for(i=0; i<5; i++)
{
sum = sum + *(a+i);
}
printf(“%d\n”, sum);
}

Ans: Sum of array elements


What is the output?

int main()
{
int val = 5;
int* ptr = &val;
printf(“%d %d”,val,(*ptr)++);
return 0;
}

Ans: 6 5


What is the output?

void main()
{
int arr[ ] = {10,20,30,40,50,60,70};
int *i, *j;
i = &arr[1];
j = &arr[5];
printf(“%u \n” , j – i );
printf(“%d \n” , *j – *i );
}

Ans: 4   40


What is the output?

int main(void)
{
int x = 5;
int *p1, *p2;
p1 = &x;
p2 = p1;
printf(“%u”,p2);
return 0;
}

Asn: Address of x


What is the output?

void main()
{
int a[5] = {10, 20, 30, 40 , 50};
int i;
for(i=0; i<5; i++)
{
printf(“Value of a[%d] = %d \t” , i, a[i]);
printf(“Address of a[%d] = %u \n” , i, &a[i]);
}
}

Ans: a[0]=10    a[1]=20    a[2]=30    a[3]=40    a[4]=50

     Addresses of all elements of an array.


What is the output?

void main()
{
int a[5] = {10,20,30,40,50};
int i;
for(i=0; i<5; i++)
{
printf(“Value of a[%d] = %d \t” , i, *(a+i));
printf(“Address of a[%d] = %u \n”, i, a+i);
}
}

Ans:    All elements of an array are displayed.

            All the addresses of an array elements are displayed.


What is the output?

void main()
{
int a[5] = {10, 20, 30 ,40, 50};
int i;
for(i=0; i<5; i++)
{
printf(“%d \t” , a[i]);
printf(“%d \t” , *(a+i));
printf(“%d \t” , *(i+a));
printf(“%d \n” , i[a]);
}
}

OutPut:

10 10 10 10 10
20 20 20 20 20
30 30 30 30 30
40 40 40 40 40
50 50 50 50 50


Attend Free Demo and Learn   C LANGUAGE ONLINE TRAINING   by Real-Time Expert

Share this post