C ,C++, SQL,PL/SQL Search Engine
-------------------------------------------------
Custom Search
Java,Advance Java,Java script and ebook Search Engine
Big collection of c and java questions
Explanations of questions in easily way
MCQ Questions in c
-------------------------------------------------
(1)
void main(){
clrscr();
printf("%d",sizeof(3.8));
getch();
}
Which of the following is true?
(a)4
(b)8
(c)10
(d)Compiler error
(e)None of these
-------------------------------------------------
(2)
void main(){
char *str1="powla";
char *str2="er";
clrscr();
printf("%s\b\b%s",str1,str2);
getch();
}
Which of the following is true?
(a)powlaer
(b)pow
(c)power
(d)Compiler error
(e)None of these
-------------------------------------------------
(3)
void main(){
int a=270;
char *p;
p=(char *)&a;
clrscr();
printf("%d",*p);
getch();
}
Which of the following is true?
(a)270
(b)address of variable a
(c)16
(d)Compiler error
(e)None of these
-------------------------------------------------
(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;
}
-------------------------------------------------
(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();
}
-------------------------------------------------
(6)
Draw memory representation of
struct xxx{
char a;
int b;
char c;
};
-------------------------------------------------
(7)
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”);
}
}
-------------------------------------------------
(8)
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();
}
Which of the following is true?
(a)I know C
I Know C
(b)I know C
I don’t know C
(c)I don’t know C
I know C
(d)Compiler error
(e)None of these
-------------------------------------------------
(9)
#define power(a) #a
void main(){
clrscr();
printf("%d",*power(432));
getch();
}
Which of the following is true?
(a)*”432”
(b)432
(c)16
(d)32
(e)Compiler error
-------------------------------------------------
(10)
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]);
}
Which of the following true?
(a)2
(b)-2
(c)3
(d)-3
(e)Compiler error
-------------------------------------------------
(11)
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;
}
-------------------------------------------------
(12)
Write a c program to find the HCF of any two numbers?
-------------------------------------------------
(13)
void main(){
int a=5;{
a++;
}
clrscr();
printf("%d",a);
getch();
}
Which of the following is true?
(a)5
(b)6
(c)7
(d)Compiler error
(e)None of these
-------------------------------------------------
(14)
void main(){
int a=5;{
int a=7;
a++;
printf(“%d”,a);
}
clrscr();
printf("%d",a);
getch();
}
Which of the following is true?
(a)5 7
(b)5 8
(c)8 5
(d)7 5
(e)Compiler error
-------------------------------------------------
-------------------------------------------------
Answer:
(1)(b)
(2)(c)
(3)(c)
(4) See in explanation.
(5) See in explanation.
(6) See in explanation.
(7) See in explanation.
(8)(c)
(9)(c)
(10)(b)
(11) See in explanation.
(12) See in explanation.
(13)(b)
(14)(c)
-------------------------------------------------
Explanation:
-------------------------------------------------
(1) 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.
(2) \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.
(4) Function sort returning a value but we are not using return value so there is wastage of two byte memory. So missing statement is, there should statement which uses the return value.
(5)
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();
}
(7)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();
}
(8)
far pointer always compare its whole far address. Since both or not equal so first output is: I don’t know C
Huge pointer always compare its physical address both c and d are representing same physical address so a and b are equal.
(9) # is string zinging operator. It makes 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
(10) We are passing the array by xxx function. 1[ch] means *(ch+1) which is ch[1] =2.
(11) Both and b are char * type but c is char * type while d is char type.
(12) 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();
}
(14) Scope of the auto variable is within {} if it is declared in {}.Also local variable has more priority than global variable.
-------------------------------------------------
Sunday, 25 October 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment