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.
Questions
#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]);
}
- 0 Garbage Value 2
- 0 1 2
- 1 2 3
- None of the above
void main()
{
int a = 123, b = 456;
a ^= b ^= a ^= b;
printf("%d %d",a,b);
}
- 123 456
- 123 123
- 456 456
- 456 123
void main()
{
int a=5,b=4,c=10;
*((a>b) ? &a : &b) = (a+b>c);
printf(%d %d,a,b);
}
- Syntax error
- Fatal error
- 0 4
- System hangs
void f(int *ip)
{
static int dummy = 5;
ip = &dummy;
printf(%u,ip);
}
void main()
{
int *ip;
f(ip);
printf(%u,ip);
}
- Some values
- 0 Some value
- Error
- None of the above
void main()
{
int realarray[2]={1,2};
int *array = &realarray[-1];
int i;
for(i=0;i<2;i++)
{
printf(" %d",*array);
array++;
}
}
- Error
- Garbage Value 1
- 0 1
- 1 2
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
- 0
- No output
- Error
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);
}
- 0 -200 300 10 4
- 300 -200 300 10 4
- -200 300 10 4 0
- 100 -200 300 4 10
main()
{
extern i;
printf("%d",i);
{
int i=20;
printf("%d",i);
}
}
- 20 20
- Garbage Value 20
- 0 20
- Linker Error
#define Str(x) #x
#define Xstr(x) Str(x)
#define OP plus
void main()
{
char *opname = Xstr(OP);
printf(%s,opname);
}
- Plus
- Compilation Error
- Runtime Error
- Linker Error
void main()
{
int i;
for (i=5; ++i; i-=3)
printf("%d ",i);
}
- Program Hangs
- No Output
- 6 4 2
- 5 2
What will be the output of the following program?
void main()
{
int val=1234;
int* ptr=&val;
printf("%d %d",val,*ptr++);
}
- 1234 1234
- 1235 1235
- 1234 1235
- 1235 1234
What will be the output of the following program?
void func()
{
printf("Testing...Done");
}
void main()
{
func;
func();
}
- Compile-Time Error
- Testing...Done
- Testing...Done
- None of these
A signed int bitfield 1-bit wide can only hold the values
- 0 and 1
- 0 and -1
- 0, 1 and -1
- None of these
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]);
}
- Compile-Time Error
- 0.0 0.0 0.0 0.0 0.0
- 0.0 0.1 0.2 0.3 0.4
- 1.0 1.0 1.0 1.0 1.0
void main()
{
int _;
=100;
printf("%d",);
}
- 100
- Linker Error
- Run Time Error
- Compiler Error
#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);
}
- 3 0
- 5 3
- 3 5
- 5 0
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);
- 10
- 11
- 1
- 0
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);
}
- Outputs 12
- Outputs 10
- Outputs the address of v
- No output
What does the line containing "break;" do in the following code?
void afunction()
{
if(1)
{
break;
afunction();
printf("Error");
}
}
- Breaks out of the if statement
- Exits the function
- Compiler error
- Nothing
void main()
{
int choice=2;
switch(choice)
{
default:
printf("Default1");
case 1:
printf("Case1");
<b>break</b>;
default:
printf("Default2");
}
}
- Compile-Time Error
- Default1Case1
- Default2
- Default1
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;
- float, int pointer
- float pointer, int pointer
- float, int
- float pointer, int
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);
}
- 25
- 11
- Error
- Garbage Value
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);
}
- 100
- 200
- Compiler Error
- None of the above
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;
}
}
- A
- B
- All the above
- None of the above