You are on page 1of 20

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.

com/LatestOffCampus

LgSoft Programming Latest Sample Placement Paper


1. What will be the output of the following program? #include main() { printf("%x",-1<<4); } ANS: fffffff0 2. What will be the output of the following program? #include <stdio.h> #define DEBUG(args) (printf("DEBUG: "), printf args) main() { int n = 0,i = 0 ; printf("%d\n", n); if(n != 0) DEBUG(("n is %d\n", n)); DEBUG(("%d",i)); } ANS: 0 DEBUG: 0 3. What will be the output of the following program? #include ##include main() { typedef union { int a; char b[10]; float c;
Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

} Struct; Struct x,y = {100}; x.a = 50; strcpy(x.b,"hello"); x.c = 21.50; printf("Union x : %d %s %f \n",x.a,x.b,x.c ); printf("Union y : %d %s %f \n",y.a,y.b,y.c); } ANS: Union x : 1101791232 21.500000 Union y : 100 d 0.000000 4. What will be the output of the following program? #include <stdio.h> #include<malloc.h> #include<string.h> main() { char *s2, *s1 ; // s1 = malloc(sizeof(char) * 1000); s1 = "Hello, "; // s2 = malloc(sizeof(char) * 10); s2 = "world!"; strcat(s1, s2); printf("%s", s2); } ANS: Segmentation fault 5. What will be the output of the following program? #include<stdio.h> main() { int i=4;
Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

printf("%d %d %d",++i,i++,i*i); printf("\n"); printf("%d %d %d",i*i,++i,i++); } ANS: 6 4 16 64 8 6 6. What will be the output of the following program? #include <stdio.h> main() { int i ; i = 1; i= i+2*i++; printf("i is now %d",i); } ANS: i is now 4 7. What will be the output of the following program? #include <stdio.h> #define DEBUG(args) (printf("DEBUG: "), printf args) main() { int n = 10; if(n != 0) DEBUG(("n is %d\n", n)); } ANS: DEBUG: n is 10 8. What will be the output of the following program? #include<stdio.h> int main(int k) { if(k<10)
Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

printf("%d ",main(k+1)); return k; } ANS: 10 9 8 7 6 5 4 3 2 9. What will be the output of the following program? #include <stdio.h> main() { int i; struct { int left,y; }a; printf("%5d\n",a[i].left); } ANS: error: subscripted value is neither array nor pointer 10. What will be the output of the following program? #include<stdio.h> #include<stdlib.h> main() { int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",*ptr++); } ANS: 4 11. What will be the output of the following program? #include <stdio.h> main() {
Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

char c1,c2,c3; c1 = getc(stdin); putc(c1,stdout); // c2 = getche(); // putc(c2,stdout); c3 = getchar(); putc(c3,stdout); } ANS: getchar=> This is a standard function that gets a character from the stdin. getch=> This is a nonstandard function that gets a character from keyboard, does not echo to screen. getche=>This is a nonstandard function that gets a character from the keyboard, echoes to screen. Use getchar if you want it to work on all compilers. Use getch or getcheon a system that supports it when you want keyboard input without pressing [Enter]. And note that the return value of all three is int! You need this to properly check for EOF. 12. What will be the output of the following program? #include<stdio.h> main() { float x=3.14; printf("%e, %E, %f",x,x,x); } ANS: 3.140000e+00, 3.140000E+00, 3.140000 13. What will be the output of the following program? #include <stdio.h> #include<malloc.h> struct test{
Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

int f; }; struct test* f(struct test * (*fPtr)() ) { struct test *ptr = (struct test*) malloc(sizeof(struct test)); return ptr; } main() { f(f)->f; } ANS: "Successfully compiles without any error" 14. What will be the output of the following program? #include<stdio.h> main() { int x=5,p=10; printf("%*d",x,p); } ANS: 10" [answer is the part inside the quotes]. 15. What will be the output of the following program? #include <stdio.h> void print_in_reverse( char *str ) { if( *str == '\0' ) return; print_in_reverse(str+1); printf( "%c" , *str ); } main()
Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

{ print_in_reverse( "char *str" ); } ANS: rts* rahc 16. What will be the output of the following program? #include <stdio.h> abc(int *i, int *j) { *i = *i + *j; *j = *i - *j; *i = *i - *j; } main() { int i = 5, j=10; abc(&i,&j); printf("%d..%d",i,j); } ANS: 10..5 17. What will be the output of the following program? #include <stdio.h> #include<math.h> //#define sqrt(x) (( x < 0) ? sqrt(-x) : sqrt(x)) main() { int y; y = sqrt(-9); printf("%d",y); } ANS: (.text+0x32): undefined reference to `sqrt' collect2: ld returned 1 exit status
Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

18. What will be the output of the following program? #include <stdio.h> main() { int i=6,j=4; printf("NO\n"); switch(i) { do{ case 1: printf("yes\n"); case 2: case 3: case 4: case 5: case 6: j--; }while (j); } } ANS: NO yes yes yes 19. What will be the output of the following program? #include <stdio.h> main()
Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

{ char as[] = "\\0\0"; int i = 0; do{ switch( as[i++]){ case '\\' : printf("A"); break; case 0 : printf("B"); break; default : printf("C"); break; } } while(i<3); } ANS: ACB 20. What will be the output of the following program? #include <stdio.h> funct(str) { printf("%s\n",str); } main() { funct('-'-'-'+"DEShaw"); } ANS: DEShaw 21. What will be the output of the following program? #include <stdio.h> main()
Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

{ struct emp { char name[20]; int age; float sal; }; struct emp e = {"Tiger"}; printf("\n%d %f",e.age,e.sal); } ANS: 0 0.000000 22. What will be the output of the following program? #include <stdio.h> main() { int a,b; scanf("%d %d", &a, &b); printf("%d\n", a+++b); printf("%d %d\n",a,b); } ANS: The value of a+++b is = a+b The value of a is incremented only after that print statement 23. What will be the output of the following program? #include <stdio.h> main() { int c; while((c=getchar()) != 0){ printf("%c",c); } }
Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

ANS: -->>Output::what even is taken as input until we terminate it. 24. What will be the output of the following program? #include <stdio.h> main() { int arr[3][3] = {1,2,3,4,5,6,7,8,9}; int i,j; for (j=2;j>=0;j--){ for(i=2;i>=0;i--){ printf("\n%d",*(*(arr+i)+j)); printf("\n TATATATA"); } } } ANS: 9 TATATATA 6 TATATATA 3 TATATATA 8 TATATATA 5 TATATATA 2 TATATATA 7 TATATATA 4 TATATATA 1
Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

TATATATA 25. What will be the output of the following program? #include <stdio.h> main() { printf("hello"); fork(); } ANS: hellohello 26. What will be the output of the following program? #include <stdio.h> int n, R; main() { R = 0; scanf("%d",&n); printf("\n %d, %d",fun(n),R); } int fun(int n) { if (n>3) return R = 5; R = 6; return(1); } ANS: prints 5 if input n>3 else prints that number. 27. What will be the output of the following program? #include <stdio.h> f( ) { printf("I am f()"); }
Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

extern f1(); main() { int i=10; f1(i); } f1(int i ) { printf("the i value is %d",i); f(); } ANS: the i value is 10I am f() 28. What will be the output of the following program? #include <stdio.h> int *NEXT(register int i) { int *ipt; ipt = &i; ipt++; return ipt; } main () { int j; printf("%d",(NEXT(j))); } ANS: In function NEXT: error: address of register variable i requested. 29. What will be the output of the following program? #include <stdio.h> #define abs(x) x>0?x:-x
Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

#define mabs(x) (((x)>=0)?(x):-(x)) int kabs(int); main() { printf("\n%d %d",abs(10)+1,abs(-10)+1); printf("\n%d %d",mabs(10)+1,mabs(-10)+1); printf("\n%d %d\n",kabs(10)+1,kabs(-10)+1); } int kabs(int n) { return(n>0? n: -n); } ANS: 10 11 11 11 11 11 30. What will be the output of the following program? #include <stdio.h> main() { char input[] = "SSSWILTECH1\1\1"; int i, c; for ( i=2; (c=input[i])!='\0'; i++) { switch(c) { case 'a': putchar ('i'); continue; case '1': break; case 1: while (( c = input[++i]) != '\1' && c!= '\0'); case 9: putchar('S'); case 'E': case 'L': continue;
Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

default: putchar(c);continue; } putchar(' '); } putchar('\n'); } ANS: SWITCH S 31. What will be the output of the following program? #include <stdio.h> unsigned char f(unsigned n) { static const unsigned char table[64] = { 0, 0, 0, 9, 0, 0, 10, 1, 0, 0, 0, 0, 0, 11, 2, 21, 7, 0,0, 0, 0, 0, 0,15, 0, 0, 12, 0, 17, 3, 22, 27,32, 8, 0, 0,0, 0, 0, 20, 6, 0, 0, 14,0, 0, 16, 26,31, 0, 0, 19, 5, 13,0, 25, 30, 18, 4, 24, 29, 23, 28, 0 }; return table[((n & -n) * 0x1d0d73df) >> 26]; } main() { printf("%c",f(8)); } ANS: "Nothing is printed" 32. What will be the output of the following program? #include <stdio.h> main() { int i; char c;
Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

for (i=0;i<5;i++){ scanf("%d",&c); printf("%d",i); } } ANS: 01234[if input is a character] else it is 0 33. What will be the output of the following program? #include <stdio.h> main() { extern int i; i=20; printf("%d\n",sizeof(i)); } ANS: Error Message: "In function `main': undefined reference to `i' ld returned 1 exit status" 34. What will be the output of the following program? #include <stdio.h> void fun(int, int*); main() { int j,i; int * intptr; printf("enter an integer\n"); scanf("%d",&i); intptr = &j; j = i; printf("i and j are %d %d \n",i,j); fun(j,intptr);
Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

printf("i is:%d",i); printf("\n j is:%d",j); } void fun(int k, int *iptr) { k++; (*iptr)++; return; } ANS: enter an integer (x) i and j are x x i is:x j is:x+1 35. What will be the output of the following program? #include <stdio.h> #define INTPTR int * main() { INTPTR pi, pj; int i,j; i=10;j=20; pi = &j; pj = &j; j++; i= *pi; printf("%d,",i); j++; // i= *pj; printf("%d",pj); } ANS: 21,-1079833692
Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

36. What will be the output of the following program? #include <stdio.h> main() { int i=4,j=2,k=0; char c1='a',c2='b'; if(k==0)printf("k is zero\n"); else if(j==2)printf("j is 2\n"); else if(i==4)printf("i is 4\n"); if(c1!='a')printf("c1 is not a\n"); else if (c2=='a')printf("c2 is b"); else printf("Hello\n"); } ANS: k is zero Hello 37. What will be the output of the following program? #include <stdio.h> main() { int i = 3,j; j = add(++i); printf("i = %d *p= %d\n", i, j); } add(ii) int ii; { ii++; printf("ii = %d\n", ii); } ANS:ii = 5 i = 4 *p= 7
Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

38. What will be the output of the following program? #include <stdio.h> #include<string.h> main() { char *str ="India pvt. ltd."; char *str1 = "DESIS"; printf("str is %s",str); printf("str is %s",str1); strcpy(str,str1); printf("str is %s",str); } ANS: Segmentation fault 39. What will be the output of the following program? #include <stdio.h> #define MAXI 100 main(){ int done,i,x=6; done=i=0; while (i < MAXI && !done){ if ((x/=2)>1){ i++; continue;} done++; } printf("%d %d\n",i,done); } ANS: 1 1 40. What will be the output of the following program? #include <stdio.h> main() {
Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

char str[] ="abcdef"; printf("str is %s",str); str = "DESIS"; printf("str is %s",str); } ANS: The first print statement prints "DESIS" but since str cannot be assigned "DESIS" thus error occurs.

Visit www.latestoffcampus.com for placement papers, interview tips & job updates. Togetfreeupdatestomailhttp://groups.google.com/group/latestoffcampus/subscribeLive updates on Facebook @ www.facebook.com/LatestOffCampus

You might also like