What will be output ?
(1) void main()
{
clrscr();
printf("%d",sizeof(3.8));
getch();
}
output: 8
Explanation: 3.8f is float constant, 3.8 is double constant and 3.8L is long double constant .Here are finding size of double constantan which is 8.
For more detail click here (data type)
(2) What will be output ?
void main()
{
char *str1="powla";
char *str2="er";
clrscr();
printf("%s\b\b%s",str1,str2);
getch();
}
output: power
Explanation: \b escape sequence back the cursor one position left .We are using two /b so after writing str1 cursor is at the position of l of powal .So when it write er it will override the la so output will be power.
(3)What will be output ?
void main()
{
int a=270;
char *p;
p=(char *)&a;
clrscr();
printf("%d",*p);
getch();
}
output: 16
(4)What is missing statement of in the following program ?
Void main()
{
int sort(int,int);
int I;
i=sort(5,6);
}
Int sort(int a,int b)
{
int c;
c=a;
a=b;
b=c;
return a;
}
Ans: Function sort returning a value but we are not using return value so there is weastge of two byte memory. So missing statement is ,there should statement which uses the return value.
(5)Write following in term of if and else :
void main()
{
int a=1,b=2,c=3;
clrscr();
if(a==5&&b==6&&c==7)
printf("india");
else
printf("pak");
getch();
}
Ans:
void main()
{
int a=1,b=2,c=3;
clrscr();
if(a==1)
{
if(b==2)
{
if(c==3)
{
printf("india");
}
else
{
printf("pak");
}}
else
{
printf("pak");
} }
else
{
printf("pak");
}
getch();
}
(q)
Give the memory representation of
Struct xxx
{
char a;
int b;
char c;
};
Ans: Memory representation :
More detail click here (union)
(q) Write the following program in term of switch and case ?
void main()
{
int a=3;
if(x>2)
{
printf(“INDIA IS BEST”);
}
else
{
printf(“PAK IS BEST”);
}
}
Ans: if condition always return two value.
1 if condition is true.
0 if condition is false.
So program is
void main()
{
int x=3;
switch(x>2)
{
case 0:printf("India is best");
break;
case 1:printf("Pak is best");
}
getch();
}
(q)
void main()
{
int far *a=(int far*)0x50000011;
int far *b=(int far*)0x50010001;
int huge *c=(int huge*)0x50000011;
int huge *d=(int huge*)0x50010001;
clrscr();
if(a==b)
printf("I know C");
else
printf("I don't know C");
if(c==d)
printf("\nI know C");
else
printf("\nI don't know C");
getch();
}
Output:
I don’t know C
I known C
Explanation: far pointer always compare its whole far address.Since both or not eaual so first output is :I don’t know C
Huge pointer always compare its physical adderss both c and d are representing same physical address so a and b are equql.
More detail click here
(q) What will be output ?
#define power(a) #a
void main()
{
clrscr();
printf("%d",*power(432));
getch();
}
Output : 52
Explanation:
# is stringzinging operator. It make the string constant of any data. So 432 is converted into “432” by macro power .Now *”432” means first char which is 4.Since we are using %d so it will print ascii value of char 4 i.e 52
More detail click here (prepro)
(q) What will be output ?
void main()
{
int arr[]={1,2,3,4,5,6};
void xxx(int[5]);
xxx(arr);
getch();
}
void xxx(int ch[5])
{
clrscr();
printf("%d",-1[ch]);
}
Output : -2
Explanation:
We are passing the array by xxx function. 1[ch] means *(ch+1) which is ch[1] =2.
(q) What is difference between a,b,c and in following declaration ?
#define xxx char *
typedef char * yyy;
void main()
{
yyy a,b;
xxx c,d;
}
Ans: Both and b are char * type but c is char * type while d is char type.
(q) Write a c program to find the HCF of any two number ?
Ans:
void main()
{
int a,b,c;
scanf(“%d%d%d”,a,b,c);
clrscr();
while((c=a%b)!=0)
{
a=b;
b=c;
}
printf("%d",b);
getch();
}
(q) What will be output ?
void main()
{
int a=5;
{
a++;
}
clrscr();
printf("%d",a);
getch();
}
Ans :6
q) What will be output ?
void main()
{
int a=5;
{
int a=7;
a++;
printf(“%d”,a);
}
clrscr();
printf("%d",a);
getch();
}
Output: 8 5
Explanation: Scope of the auto variable is within {} if it is declared in {}.Also local variable has more priority than global variable.
The Vera Zvonareva Picture
-
*Vera Zvonareva*
NEW YORK CITY, NEW YORK
*V. ZVONAREVA/K. Kanepi6-3, 7-5*
THE MODERATOR: Questions, please.
*Q. Crazy, crazy kind of weather out...
13 years ago
No comments:
Post a Comment