printf , scanf question in c language | CTechnotips

Printf function questions and answer with solution

Printf objective types interview questions and answers  

(1) What will output when you compile and run the below code?
#include<stdio.h>
#include<conio.h>
void main()
{
int a=5,b=6,c=11;
clrscr();
printf("%d %d %d");
getch();
}
(a)Garbage value garbage value garbage value
(b)5 6 11
(c)11 6 5
(d)Compiler error
Answer: (c)
 

(2) What will output when you compile and run the below code?
#include<stdio.h>
void main()
{
char *str="CTECHNOTIPS";
clrscr();
printf(str+7);
getch();
}

(a)CTECHNOTIPS
(b)CTECHNO
(c)TIPS
(d)Compiler error
Answer: (c)


(3) What will output when you compile and run the Below code?
#include<stdio.h>
void main()
{
clrscr();
printf("%d",printf("CTECHNOTIPS"));
getch();
}
(a)11CTECHNOTIPS
(b)CTECHNOTIPS11
(c)Garbage CTECHNOTIPS
(d)Compiler error
Answer: (b)


(4) What will output when you compile and run the Below code?
 
#include<stdio.h>
#include<conio.h>
void main()
{
short int a=5;
clrscr();
printf("%d"+1,a);
getch();
}
(a)6
(b)51
(c)d
(d)Compiler error
Answer: (c)


(5) What will output when you compile and run the Below code?
#include<stdio.h>
void main()
{
int i=85;
clrscr();
printf("%p %Fp",i,i);
getch();
}

(a)85 85
(b)0055 034E:0055
(c)0055 FFFF:0055
(d)Compiler error
Answer: (b)
 

(6)  What will output when you compile and run the Below code?
 
#include<stdio.h>
static struct student
{
int a;
    int b;
    int c;
int d;
}s1={6,7,8,9},s2={4,3,2,1},s3;
void main()
{
s3=s1+s2;
clrscr();
printf("%d %d %d %d",s3.a,s3.b,s3.c,s3.d);
getch();
}

(a)6789
(b)4321
(c)10101010
(d)Compiler error
Answer: (d)


(7) What will output when you compile and run the Below code?
 
#include<stdio.h>
extern struct student
{
int a;
    int b;
    int c;
int d;
}s={6,7,8,9};
void main()
{
clrscr();
printf("%d %d %d %d",s.a,s.b,s.c,s.d);
getch();
}
(a)6789
(b)9876
(c)0000
(d)Compiler error
Answer: (a)


(8) What will output when you compile and run the Below code?
 
#include<stdio.h>
struct student
{
static int a;
register int b;
auto int c;
extern int d;
}s={6,7,8,9};
void main()
{
printf("%d %d % %d",s.a,s.b,s.c,s.d);
}
(a)6789
(b)9876
(c)0000
(d)Compiler error
Answer: (d)


 (9)What will output when you compile and run the Below code?
 
#include<stdio.h>
struct student
{
int roll;
int cgpa;
int sgpa[8];
};
void main()
{
struct student s={12,8,7,2,5,9};
int *ptr;
ptr=(int *)&s;
clrscr();
printf("%d",*(ptr+3));
getch();
}

(a)8
(b)7
(c)2
(d)Compiler error
Answer: (c)


(10) What will output when you compile and run the Below code?
 
#include<stdio.h>
struct game
{
int level;
int score;
struct player
{
char *name;
}g2={"anil"};
}g3={10,200};
void main()
{
struct game g1=g3;
clrscr();
printf("%d  %d  %s",g1.level,g1.score,g1.g2.name);
getch();
}
(a)10 200 anil
(b)200 10 anil
(c)10 200 null
(d)Compiler error
Answer: (d)


(11)What will output when you compile and run the Below code?
 
#include<stdio.h>
struct game
{
int level;
int score;
struct player
{
char *name;
}g2;
}g1;
void main()
{
clrscr();
printf("%d  %d  %s",g1.level,g1.score,g1.g2.name);
getch();
}
(a)Garbage_value garbage_value garbage_value
(b)0 0 (null)
(c)Run time error
(d)Compiler error
Answer: (b)

0 comments:

Post a Comment