C Programming Advanced Concepts

Practice tests covering advanced C programming concepts including pointers, arrays, macros, operators, recursion, and control flow. Prepare for GATE, BCA, B.Sc-IT, M.Sc-IT, and MCA entrance exams.

25 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

#include<stdio.h>
#include<conio.h>
main()
{
int a[3],i;
for(i=0;i<3;i++)
a[i]=i++;
for(i=0;i<3;i++)
printf(" %d",a[i]);
}

  1. 0 Garbage Value 2
  2. 0 1 2
  3. 1 2 3
  4. None of the above
Question 2 Multiple Choice (Single Answer)

void main()
{
int a = 123, b = 456;
a ^= b ^= a ^= b;
printf("%d %d",a,b);
}

  1. 123 456
  2. 123 123
  3. 456 456
  4. 456 123
Question 3 Multiple Choice (Single Answer)

void main()
{
int a=5,b=4,c=10;
*((a>b) ? &a : &b) = (a+b>c);
printf(%d %d,a,b);
}

  1. Syntax error
  2. Fatal error
  3. 0 4
  4. System hangs
Question 4 Multiple Choice (Single Answer)

void f(int *ip)
{
static int dummy = 5;
ip = &dummy;
printf(%u,ip);
}
void main()
{
int *ip;
f(ip);
printf(%u,ip);
}

  1. Some values
  2. 0 Some value
  3. Error
  4. None of the above
Question 5 Multiple Choice (Single Answer)

void main()
{
int realarray[2]={1,2};
int *array = &realarray[-1];
int i;
for(i=0;i<2;i++)
{
printf(" %d",*array);
array++;
}
}

  1. Error
  2. Garbage Value 1
  3. 0 1
  4. 1 2
Question 6 Multiple Choice (Single Answer)

What will be the output of the given function?void main()
{
int a=1,b=2,c=3,d=4;
printf("%d",!a?b?!c:!d:a);
}

  1. 1
  2. 0
  3. No output
  4. Error
Question 7 Multiple Choice (Single Answer)

int main()
{
int a=500,b=100,c=30,d=40,e=19;
a+=b-=c*=d/=e%=5;
printf("%d %d %d %d %d",a,b,c,d,e);
}

  1. 0 -200 300 10 4
  2. 300 -200 300 10 4
  3. -200 300 10 4 0
  4. 100 -200 300 4 10
Question 8 Multiple Choice (Single Answer)

main()
{
extern i;
printf("%d",i);
{
int i=20;
printf("%d",i);
}
}

  1. 20 20
  2. Garbage Value 20
  3. 0 20
  4. Linker Error
Question 9 Multiple Choice (Single Answer)

#define Str(x) #x
#define Xstr(x) Str(x)
#define OP plus
void main()
{
char *opname = Xstr(OP);
printf(%s,opname);
}

  1. Plus
  2. Compilation Error
  3. Runtime Error
  4. Linker Error
Question 10 Multiple Choice (Single Answer)

void main()
{
int i;
for (i=5; ++i; i-=3)
printf("%d ",i);
}

  1. Program Hangs
  2. No Output
  3. 6 4 2
  4. 5 2
Question 11 Multiple Choice (Single Answer)

What will be the output of the following program?
void main()
{
int val=1234;
int* ptr=&val;
printf("%d %d",val,*ptr++);
}

  1. 1234 1234
  2. 1235 1235
  3. 1234 1235
  4. 1235 1234
Question 12 Multiple Choice (Single Answer)

What will be the output of the following program?

void func()
{
printf("Testing...Done");
}
void main()
{
func;
func();
}

  1. Compile-Time Error
  2. Testing...Done
  3. Testing...Done
  4. None of these
Question 13 Multiple Choice (Single Answer)

A signed int bitfield 1-bit wide can only hold the values

  1. 0 and 1
  2. 0 and -1
  3. 0, 1 and -1
  4. None of these
Question 14 Multiple Choice (Single Answer)

What will be the output of the following program?
void main()
{
int i;
float a[5];
for (i=0; i<5; i++)
a[i] = (printf, ("%d",i/10.0));
for (i=0; i<5; i++)
printf("%.1f ",a[i]);
}

  1. Compile-Time Error
  2. 0.0 0.0 0.0 0.0 0.0
  3. 0.0 0.1 0.2 0.3 0.4
  4. 1.0 1.0 1.0 1.0 1.0
Question 15 Multiple Choice (Single Answer)

void main()
{
int _;
=100;
printf("%d",
);
}

  1. 100
  2. Linker Error
  3. Run Time Error
  4. Compiler Error
Question 16 Multiple Choice (Single Answer)

#define big(a,b) a > b ? a : b
#define swap(a,b) temp=a; a=b; b=temp;
void main()
{
int a=3,b=5,temp=0;
if ((3+big(a,b)) > b)
swap(a,b);
printf("%d %d",a,b);
}

  1. 3 0
  2. 5 3
  3. 3 5
  4. 5 0
Question 17 Multiple Choice (Single Answer)

Evaluate the following:

int fn(int v)
{
if(v==1 || v==0)
return 1;
if(v%2==0)
return fn(v/2)+2;
else
return fn(v-1)+3;
}
for fn(7);

  1. 10
  2. 11
  3. 1
  4. 0
Question 18 Multiple Choice (Single Answer)

What does the following code do?

void afunction(int *x)
{
x=new int;
*x=12;
}
int main()
{
int v=10;
afunction(&v);
printf(“%d”,v);
}

  1. Outputs 12
  2. Outputs 10
  3. Outputs the address of v
  4. No output
Question 19 Multiple Choice (Single Answer)

What does the line containing "break;" do in the following code?

void afunction()
{
if(1)
{
break;
afunction();
printf("Error");
}
}

  1. Breaks out of the if statement
  2. Exits the function
  3. Compiler error
  4. Nothing
Question 20 Multiple Choice (Single Answer)

void main()
{
int choice=2;
switch(choice)
{
default:
printf("Default1");

     case 1:
        printf(&quot;Case1&quot;);
        <b>break</b>;

     default:
        printf(&quot;Default2&quot;);
  } 
}
  1. Compile-Time Error
  2. Default1Case1
  3. Default2
  4. Default1
Question 21 Multiple Choice (Single Answer)

What are the types of variable f2 and p2 in the following declaration?

#define floatptr float *
#define int * intptr

floatptr f1,f2;
intptr p1,p2;

  1. float, int pointer
  2. float pointer, int pointer
  3. float, int
  4. float pointer, int
Question 22 Multiple Choice (Single Answer)

What would be the output of the following?

#define SQR(x) x*x
main()
{
int a,b=3;
a=SQR(b+2);
printf(“%d”,a);
}

  1. 25
  2. 11
  3. Error
  4. Garbage Value
Question 23 Multiple Choice (Single Answer)

What will be the output of the following program?

void func()
{
printf("Testing...Done");
}
void main()
{
func;
func();
}What would be the output of the following?

main()
{
int a=10,b;
a>=5?b=100:b=200;
printf("%d",b);
}

  1. 100
  2. 200
  3. Compiler Error
  4. None of the above
Question 24 Multiple Choice (Single Answer)

What would be the output of the following?

main()
{
int i=4;
switch(i)
{
default: printf(“A”);
case 1: printf(“B”);
break;
case 2: printf(“C”);
break;
case 3: printf(“D”);
break;
}
}

  1. A
  2. B
  3. All the above
  4. None of the above