Data Structure

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

1.C program to swap two numbers 2.C program to generate and print armstrong numbers 3.

C program to reverse a number 4. C program to find minimum element in array 5. Fibonacci series in c Objective question in c 1What is the output of: #include<stdio.h> int main() { int x=40; { int x=20; printf("%d",x); } printf("%d",x); return 0; } A. 40 40 B. 20 40 C. 40 20 D. Compilation Error See Answer & Explanation Lets Discuss 2What is the output of the following program: void main( ) { int i = 2, j = 3, k, l ; float a, b ; k = i / j * j ; l = j / i * i ; a = i / j * j ; b = j / i * i ; printf( "%d %d %f %f", k, l, a, b ) ; } A. 3 3 2 2 B. 3 3 0 2.000000

C. 3 2 0.000000 3.000000 D. 0 2 0.000000 2.000000 See Answer & Explanation Lets Discuss 3What is the output of: main( ) { int a, b ; a = -3 - - 3 ; b = -3 - - ( - 3 ) ; printf ( "a = %d b = %d", a, b ) ; } A. -3 3 B. -6 0 C. 0 -6 D. None of the Above See Answer & Explanation Lets Discuss 4 C language was developed by? A. Dennis Richie B. Martin Richards C. Bill Gates D. Ken Thompson See Answer & Explanation Lets Discuss 5 A character variable can store x characters at a time: A. 1 character B. 8 character C. 256 character D. None of the above 6 What will the statement char ch='A'; store in variable ch? A. The character A B. Ascii value of character A

C. A along with inverted commas D. None of the above See Answer & Explanation Lets Discuss 7What is the output of the following program? #include <stdio.h> int main(){ int c=08; printf("%d",c); return 0; } A. 8 B. 0 C. Compile Time Error D. None of the Above See Answer & Explanation Lets Discuss 8What is the output of the following program? #include<stdio.h> void main() { printf("%d",sizeof(5.2)); } A. Compiler Error: Can't determine size of a constant B. 4 (Size of float) C. 8 (Size of double) D. Garbage Value See Answer & Explanation Lets Discuss 9What is the output of the following program? #include<stdio.h> int main(){ double d=5.2; int i=5; printf("%d\t",sizeof(!d)); printf("%d\t",sizeof(i=15/2)); printf("%d",i); return 0; }

A. 4 2 7 B. 4 4 5 C. 2 2 5 D. Compile Time Error: expression not allowed inside sizeof See Answer & Explanation Lets Discuss 10 What is the output of the following program? #include<stdio.h> int main(){ int a= sizeof(signed) +sizeof(unsigned); int b=sizeof(const)+sizeof(volatile); printf("%d",a+++b); return 0; } A 16 . B 8 . C Error: Cannot find size of modifiers. . D Error: Undefined operator +++ .

What is the output of the following program? #include<stdio.h> void main() { int a=8,b=4; int c,d; c= a>6; d= a>2 && b==3; printf("c = %d, d= %d",c,d); } A. B. C. D. See Answer & Explanation Lets Discuss

c= 1, d= 0 c= 0, d= 0 c= 0, d= 1 Compilat ion Error

2What is the output of the following program? #include<stdio.h> void main() { int i=10; switch(i) { case 1: printf(" i=1"); break; case 10: printf(" i=10"); case 11: printf(" i=11"); break; case 12: printf(" i=12"); } } A. i=10 i=11 i=12 B. i=1 i=10 i=11 i=12 C. i=10 i=11 D. None of the Above See Answer & Explanation Lets Discuss 3What is the output of the following program? #include<stdio.h> void main() { char c = 'c'; switch(c) { case 'a' : printf("inside case a,"); break; case 'b' : printf("inside case b,"); break; case 'c' : printf("inside case c,"); case 'd' : printf("inside case d,"); continue; default: printf("inside default case"); break; } } A. inside case c, inside case d B. inside case c C. inside case c, inside case d, inside default case

D. Compilation Error See Answer & Explanation Lets Discuss 4What is the output of the following program? #include<stdio.h> void main() { char c= 'a'; switch(c) { case 65 : printf("inside case A,"); break; case 97 : printf("inside case a,"); break; default: printf("inside default case"); break; } } A. inside default case B. inside case a, C. Compilation Error D. inside case A, See Answer & Explanation Lets Discuss 5What is the output of the following program? #include<stdio.h> void main() { int a=8,b=4; int c; c=(a<6) || (b=10); printf("\nc= %d, a=%d, b=%d",c,a,b); } A. c= 1, b= 4 B. c= 1, b= 10 C. c= 0, b= 4 D. Compilation Error 1 What is the output of the following program? 1 #include<stdio.h> void main()

{ int i=10; if(i ==10) printf("I is 10"); else if ( i <= 10) printf(",I is less than or equal to 10"); else { break; } } A. I is 10 B. I is 10 ,I is less than or equal to 10 C. Compile Time Error D. None of the Above See Answer & Explanation Lets Discuss 1 What is the output of the following program? 2 #include<stdio.h> void main() { int x=1; switch(x) { case x: printf("case 1"); case 2: printf("case 2"); case 3: printf("case 3"); case 4: printf("case 4"); } } A. case 1 B. case 1 case 2 case 3 case 4 C. Compile Time Error D. None of the Above 1 What is the output of the following program? #include<stdio.h> void main()

break; break; break; break;

{ int x=10,y=20; x=((x>9) && y=30 ? printf("\nTRUE"): printf("\nFALSE")); printf("\ny=%d",y); } A. FALSE y=20 B. TRUE y=30 C. Compilation Error D. None of the Above 1 Identify macro definition in below c program. #define MAX 2 //LINE 1 #define SQUARE(x) (x*x) //LINE 2 void main() { int y = MAX * SQUARE(4); //Line 5 } A. Line 1 is macro definition B. Line 2 is macro definition C. Both Line 1 & Line 2 are macro definitions D. None is macro definition See Answer & Explanation Lets Discuss 2What is the output of program? #include<stdio.h> #define MAX //LINE 2 int main() { int x =4 * MAX; printf("x=%d",x); } A. 0 B. 4 C. error at LINE 2 : macro definition expected D. error at LINE 5 : expected expression before ; token //LINE 5

See Answer & Explanation Lets Discuss 3What is the output of below program? void func() { #define SQUARE(x) x*x } int main() { int x = SQUARE(2); printf("x=%d",x); return 0; } A. 4 B. error : definition of macro is not allowed inside function C. error : Scope of SQUARE is limited to func() so undefined SQUARE macro in main() D. None See Answer & Explanation Lets Discuss 4What is the output of below program? #include<stdio.h> #define int char // Line 2 int main() { int* str="Hello"; // Line 5 printf("%s",str); return 0; } A. error : use of keyword in macro definition is not allowed at line 2 B. Warning : initialization from incompatible pointer type at line 5 C. Prints Hello without any warning and error D. Run time error See Answer & Explanation Lets Discuss 5What is the output of below program? #include<stdio.h> int main()

{ int x = SQUARE(2); printf("x=%d",x); return 0; } void func() { #define SQUARE(x) x*x } A. 4 B. error : definition of macro is not allowed inside function C. error : undefined SQUARE macro in main() D. None 1 What is the output of below c program? #include<stdio.h> int main() { displayOut(); return 0; } int displayOut() { printf("Hi from placementyogi.com\n"); } A. Compiles with no warning and error messages B. Compiles with warning: conflicting types for dispalyOut C. Does not compile, gives error : dispalyOut not declared D. Compile but throws error while linking See Answer & Explanation Lets Discuss 2 What is the output of below c program? #include<stdio.h> main() { printf("Hello from main,"); int inside() { printf("inside,"); int deepinside()

{ printf("and deepinside function\n"); } } } A. Hello from main,inside,and deepinside function B. Hello from main,inside C. Function definition inside another function is not allowed in C. D. None See Answer & Explanation Lets Discuss 3 What is the ouput of below c program? #include<stdio.h> int main() { printf("PlacementYogi"); main(); return 0; } A. Infinite loop B. Error because of stack overflow C. PlacementYogi is printed 65535 times D. Calling main() function is not allowed See Answer & Explanation Lets Discuss 4 What is the output of below c program? #include<stdio.h> int main() { void swap(int,int); int a=10,b=20; swap(a,b); //Line 6 printf("%d,%d",a,b); } void swap( int x, int y) { int temp=x; x=y; y=temp; } A. 10, 20 //Line 9

B. 20, 10 C. 10, 10 D. 20, 20 See Answer & Explanation Lets Discuss 5 What is the output of below c program? #include<stdio.h> int main() { void swap(int*,int*); //Line 4 int a=10,b=20; swap(&a,&b); //Line 6 printf("%d,%d",a,b); } void swap( int* x, int* y) //Line 9 { int temp=*x; //Line 10 *x=*y; //Line 11 *y=temp; //line 12 } A. 10, 20 B. 20, 10 C. 10, 10 D. 20, 20

You might also like