0% found this document useful (0 votes)
96 views39 pages

Programming MCQ: Practice and Discussion

The document contains several C programming code snippets and questions related to understanding the output of the code snippets. The code snippets demonstrate concepts like passing arguments to functions by value and reference, static variables, pointers, arrays, and operators. The questions test understanding of how the code works and what values would be printed as output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views39 pages

Programming MCQ: Practice and Discussion

The document contains several C programming code snippets and questions related to understanding the output of the code snippets. The code snippets demonstrate concepts like passing arguments to functions by value and reference, static variables, pointers, arrays, and operators. The questions test understanding of how the code works and what values would be printed as output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 39

Programming

MCQ
Practice and Discussion
#include “stdio.h”
int main()
{
char arr[100];
printf(“%d”, scanf(“%s”, arr));
return 1;
}

a) Error b) 100 c) 1 100 d) 1


output
d) 1
int main()
{
int a,b,c;
printf("%d", scanf("%d %d %d", &a,&b,&c));
return 1;
}
Note: Assume Input given for a,b and c is 1 2 3

a) 1 2 3 b) 1 c) 2 d) 3
output
d) 3
int main()
{
int a=1,b=2,c=3;
printf("%d", printf("%d %d %d", a,b,c));
return 1;
}
a) 3 1 2 3 b) 1 2 3 3 c) 1 2 3 6 d) 1 2 3 5
output
d) 1 2 3 5
int main()
{
int a=11,b=12,c=13;
printf("%d", printf("%d %d %d", a,b,c));
return 1;
}

a) 11 12 13 5 b) 11 12 13 7 c) 11 12 13 8 d) 11 12 13 9
output
c) 11 12 13 8
int main()
{
printf(4+"Tirunelveli");
return 1;
}
// assume the base address of “Tirunelveli” is 100.

a) None b) 4 Tirunelveli c) nelveli d) veli


output
c) nelveli
int main()
{
printf("%d ",printf(4+"Tirunelveli"));
return 1;
}

a) 1 b) 7 nelveli c) 11 Tirunelveli d) nelveli 7


output
d) nelveli 7
int main()
{
int x=5;
printf("%d %d %d", x==5, x=50, x>40);
return 1;
}

a) 1 50 1 b) 0 50 1 c) 1 50 0 d) 0 50 0
output
d) 0 50 0
int main()
{
int x=5,y=-5;
printf("%d %d %d", x==y, x=(x+y)-x, y=(x+y)-y);
return 1;
}

a) 0 -5 5 b) 0 5 -5 c) 1 -5 5 d) 1 5 5
output
d) 1 5 5
int main()
{
int a[] = {2,4,6,8,10};
int i, sum=0, *b = a+4;
printf("\n*b=a+4 equal to %d=%d + 4",*b,a[4]);
for(i=0 ; i <5 ; i++)
{
printf("\n *b-i :: %d - %d = %d \t\t ", *b,1,*b-1);
printf("-\t\t\t *(b-i) :: *(%d - %d) = *%d= %d",*b,i,b-i, *(b-i));
sum = sum + (*b-1) - *(b-i);
printf("\t\t sum = %d",sum);
}
printf("\n\n%d", sum);
}
• Output
15
int main()
{
int a[] = {10,8,6,4,2};
int i, sum=0, *b = a+4;
for(i=0 ; i <5 ; i++)
{
sum = sum + (*b-i) - *(b-i);
printf("sum = %d",sum);
}
printf("\n\n%d", sum);
}

a) 15 b) -20 c) -25 d) -30


output
d) -30
int main()
{
char a[]={'A','B','C','D'};
char *ppp = &a[0];
printf("\n a0=%c a1=%c a2=%c a3=%c *ppp=%c",a[0],a[1],a[2],a[3],*ppp);
*ppp++;
printf("\n a0=%c a1=%c a2=%c a3=%c *ppp=%c",a[0],a[1],a[2],a[3],*ppp);
printf("\n%c %c", *++ppp,--*ppp);
printf("\n a0=%c a1=%c a2=%c a3=%c *ppp=%c",a[0],a[1],a[2],a[3],*ppp);
}

a) B A b) C B c) C A d) D C
c) C A
int main()
{
int a = 32, *ptr = &a;
char ch='A', *cho = ch;
cho += a ;
printf("\ncho=%c *ptr =%d ch=%c",cho,*ptr, ch);
*ptr += ch;
printf("\n a=%c ch=%c ptr=%c",a,ch,*ptr);
}

a) a A a b) A A a c) 32 A a d) A a 32
output
a) a A a
int main()
{
int arr[] = {1,2,3,4,5,6,7,8,9,0,1,2,5} , *ip = arr+4;
printf("\n%d", ip[1]);
}

a) 4 b) 5 c) 6 d) 2
output
c) 6
int main()
{
float sum=0.0, j=1.0, i=2.0;
while (i / j > 0.0625)
{
j=j+j;
sum = sum + i/j ;
}
printf ("%f", sum);
}
a) 1.0 b) 1.5 c) 1.75 d) 1.93
output
d) 1.93
int main()
{
int a = 2016, b=0, c=4, d=42;
mystery (&a,&b);
if (a < c)
mystery(&c,&a);
mystery(&a,&d);
printf("\n %d",a);
}
void mystery(int *ptra, int *ptrb)
{ int *temp;
temp = ptrb;
ptrb = ptra;
ptra = temp; a) 2016 b) 0 c) 4 d) 42
}
output
a) 2016

void mystery(int *ptra, int *ptrb) void mystery(int *ptra, int *ptrb)
{ int *temp; { int temp;
temp = ptrb; temp = *ptrb;
ptrb = ptra; *ptrb = *ptra;
ptra = temp; *ptra = temp;
} }

d) 42
void fun()
{
static int x;
printf("%d",x);
x=x+1;
}
int main()
{
fun();
fun();
return 0;
} a) 0 0 b) 0 1 c) 1 1 d) 1 0
b) 0 1
int incr(int i)
{
static int count=0;
count = count + 1;
return (count+i);
}
int main()
{
int i,j=0 ;
for (i=0 ; i < 4 ; i++)
j += incr(j);
printf("\n j=%d",j);
return 0; a) 4 b) 8 c) 13 d) 26
}
Output

d) 26
void f1(int a, int b)
{
int c;
c=a ; a = b ; b = c;
}
void f2(int *a, int *b)
{
int c;
c=*a ; *a=*b ; *b = c;
}
int main()
{
int a=-4, b=5, c=6;
f1(a,b);
f2(&a,&b);
printf("%d",c-a-b); a) -3 b) 4 c) 5 d) 6
return 0;
}
c) 5
int funcf(int x); funcf(int x)
int funcg(int y); {
int main() int y;
{ y = funcg(x);
int x=5, y=10, count; return (y);
for (count=1 ; count <=2 ; count++) }
{ funcg (int x)
y += funcf(x) + funcg(x); {
printf("%d ", y); static int y=10;
} y += 1;
return 0; return (y+x);
} }
a) 43 43 b) 43 63 c) 43 80 d) 43 60
c) 43 80

You might also like