C Language Online Test 4

C Language Online Test 4

C Langauge Practice Programs-MCQs-Objective-QuestionsWhat 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;
}
Ans: 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]);
What is the output?
int main()
{
int i=3, *j, k;
j = &i;
printf(“%d\n”, i**j*i+*j);
return 0;
}
A. 30
B. 27
C. 9
D. 3
Ans: A


What is the output?

int main()
{
int a = 555, *ptr = &a, b = *ptr;
printf(“%d %d %d”, ++a, –b, *ptr++);
return 0;
}
Ans: 556 554 555
What is the output?
What will be the output of the program?
int main()
{
char str[20] = “Hello”;
char *const p=str;
*p=’M’;
printf(“%s\n”, str);
return 0;
}
A.Mello
B.Hello
C.HMello
D.MHello

Ans: A


What is the output?

#include <stdio.h>
int main()
{
int a[]={1,2,3,4,5,6};
int* ptr = a+2;
printf(“%d %d”,*++a, –*ptr);
return 0;
}
Ans: Lvalue Required


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


What will be the output of the program If the integer is 4bytes long?

int main()
{
int ***r, **q, *p, i=8;
p = &i;
q = &p;
r = &q;
printf(“%d, %d, %d\n”, *p, **q, ***r);
return 0;
}
A. 8, 8, 8
B. 4000, 4002, 4004
C. 4000, 4004, 4008
D. 4000, 4008, 4016

Ans: A


what is the output?

int main()
{
int a[]={1,2,3,4,5,6};
int* ptr = a+2;
printf(“%d %d”, –*ptr+1, 1+*–ptr);
return 0;
}
Ans: 2 3


What will be the output of the program if the size of pointer is 4-bytes?

int main()
{
printf(“%d, %d\n”, sizeof(NULL), sizeof(“”));
return 0;
}
A.2, 1
B.2, 2
C.4, 1
D.4, 2

Answer: Option C

Explanation:
In TurboC, the output will be 2, 1 because the size of the pointer is 2 bytes in 16-bit platform.

But in Linux, the output will be 4, 1 because the size of the pointer is 4 bytes.

This difference is due to the platform dependency of C compiler.


What will be the output of the program?

int main()
{
int arr[2][2][2] = {10, 2, 3, 4, 5, 6, 7, 8};
int *p, *q;
p = &arr[1][1][1];
q = (int*) arr;
printf(“%d, %d\n”, *p, *q);
return 0;
}
A. 8, 10
B. 10, 2
C. 8, 1
D. Garbage values

Ans: A


What will be the output of the program assuming that the array begins at the location 1002 and size of an integer is 4 bytes?

int main()
{
int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
printf(“%u, %u, %u\n”, a[0]+1, *(a[0]+1), *(*(a+0)+1));
return 0;
}
A. 448, 4, 4
B. 520, 2, 2
C. 1004, 2, 2
D. Error

Ans: C


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


What will be the output of the program ?

int main()
{
printf(“%c\n”, 7[“abcdefghij”]);
return 0;
}
A. Error: in printf
B. Nothing will print
C. print “h” of IndiaBIX
D. print “7

Answer: Option C


What will be the output of the program ?

int main()
{
char *p;
p=”hello”;
printf(“%s\n”, *&*&p);
return 0;
}
A. llo
B. hello
C. ello
D. h

Ans: B


What will be the output of the program assuming that the array begins at location 1002?

int main()
{
int a[2][3][4] = { {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 2},
{2, 1, 4, 7, 6, 7, 8, 9, 0, 0, 0, 0} };
printf(“%u, %u, %u, %d\n”, a, *a, **a, ***a);
return 0;
}
A. 1002, 2004, 4008, 2
B. 2004, 4008, 8016, 1
C. 1002, 1002, 1002, 1
D. Error

Answer: Option C


If the size of integer is 4bytes, What will be the output of the program?

int main()
{
int arr[] = {12, 13, 14, 15, 16};
printf(“%d, %d, %d\n”, sizeof(arr), sizeof(*arr), sizeof(arr[0]));
return 0;
}
A. 10, 2, 4
B. 20, 4, 4
C. 16, 2, 2
D. 20, 2, 2

Answer: Option B


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

Share this post


Azure-devops- online training
Python online traning
MS-Azure-online training
Angular9 online training
AWS online training

Specialization on Trending Courses

Linix online training
Advance Spring online training
fullstack online training
Core java onlne training
Android online training
C#-net online training
SQL online training