You are on page 1of 9

Consider the following programs and find out the output with detailed explanation. Q1.

main() { char *ptr1 = abcdef; ptr1 = ptr1 + (strlen(ptr1)-1); printf(%c,--*ptr1--); printf(%c,--*--ptr1); printf(%c,--*(ptr1--)); printf(%c,--*(--ptr1)); printf(%c,*ptr1); } Q2. main () { int a; a = 3; e(a); } void e(int a) { if(n>0) { e(--n); printf(%d,n); e(--n); } } Q3. main() { char a[]=abcdef; char * p = a; p++; p++; p[2] = z; printf( %s ,p); } ans cdzf

ans 0120

Q4. void t1 (char *); main() { char * p; p = abcdef; t1(p); } void t1(char *q) { if(*q != r) { putchar(*q); t1(q++); } } Q5. static unsigned char h [5]={1,2,3,4,5}; main() { struct ad { unsigned short a; unsigned short b; }; struct ad *it; it = (struct ad *) h; printf(%d, it->a); printf(%d, it->b); } Q6. main () { printf (%d, sizeof (65555)); printf(%d,sizeof(65555L)); printf(%d,sizeof(6.5F)); printf (%d,sizeof (6.5)); printf(%d,sizeof(6.5L)); }

Q7. main() { int q, i, j, count; i=j=0; q=2; count = 6; switch( 3 ) { case 0: while ( --count > 0 ) { case 1: ++j; case 2: ++i; case 3: ; case 4: ; case 5: ; } } printf(%d,i); printf(%d,j); } Q8. main() { char * p; char buf[10] = {1,2,3,4,5,6,7,9,8}; p = (buf + 1) [5]; printf(%d,p); } Q9. main () { float a [10][10]; float *p, *q; float *e, *f; p = &a[5][8]; q = &a[10]9];

e = p q + a; //exp1 f = a + p q; //exp2 } Which one is the right expression? Q10. main () { char *table[] = {jan,feb,march}; char **ptr = &table [1]; printf (%c, (*++*--ptr)); } Q11. main () { float a [10][10]; float *p, *q; unsigned int nu; p = &a[5][8]; q = &a[10][9]; if ((p-q) > 0) nu = p q; else nu = -(p q); printf (%d, nu); } Q12. main () { int a, b; a = 3; b = 5; a ^= b; b ^= a; a ^= b; }

Q13. main () { printf (ABCDEF+sizeof (ABC)); } Q14. char i; void try1(); void try2(char *); main() { try1(); } void try1() { static char *ptr = abcde; i = *ptr; printf (%c,i); try2(++ptr); } void try2 (char *t) { static char *pt; pt = t + strlen(t) 1; if( i != *pt--) if( t != pt ) try1 (); }

Q15. void f1 (int *,int); void f2 (int *, int); void (*p[2])(int *,int); main () { int a; int b; p[0] = f1; p[1] = f2; a = 3; b = 5; p[0] (&a , b); printf(%d %d,a,b); p[1](&a, b); printf(%d %d,a,b); } void f1 (int *p, int q) { int temp; temp = *p; *p = q; q = temp; } void f2 (int *p, int q) { int temp; temp = *p; *p = q; q = temp; }

Q16. main () { int i = 5; switch (i) { static int i; i = 3; i = i * i; case 3: i = i + i; case 4: i = i + i; case 5: i = i + i; printf (%d,i); } printf (%d,i); } Q17. main () { while (1) { int i = 0; while (i < 10) { ++i; for (;;) { if (++i < 5) continue; break; } } printf (%d,i); break; } }

Q18. void execute (int [], int, int); main() { static int a []={5,3,4,2,1,6,8}; int temp; int p, s, e, i; s = 0; p = s; e = sizeof (a) / sizeof (a[0]); for ( i = s +1 ;i<e ;i++) if (a [i]<a[s]) execute (a,++p, i); execute (a, s, p); for (i = 0; i < e; i++) printf (%d,a [i]); } void execute (int a [], int I, int j) { int temp; temp = a [I]; a [I] = a [j]; a [j] = temp; } Q19. void temp (char *); main () { char *p = abcdef; temp (p); } void temp (char *s) { char *p = ++s; while (*q) ++q; printf (%d,q-s); }

Q20. Write a shell script which gets executed the moment the user logs in. It should display the message Good Morning/Good Evening / Good Afternoon depending upon the time at which the user logs in. Q21. Write a shell script that deletes all lines containing the word Unix in the files supplied as an argument to this shell script Q22.Practice all the below mentioned commands with all possible options cd, cat, ls, ln, dir, mkdir, rmdir, pwd, mv, cp, rm, ps, kill. Q23 what is the use of PATH variable?

Q24. Practice all the below mentioned commands with all possible options chmod, head, more, tail and chgrp.

You might also like