Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
02 - C-Puzzles

02 - C-Puzzles

Ratings: (0)|Views: 84 |Likes:
Published by SrihariChidura

More info:

Published by: SrihariChidura on Jun 18, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

05/11/2014

pdf

text

original

 
C Puzzles : Questions and Answers - Level 1
Questions
L1.Q1 : Write the output of the following program
#include#defineABC20#define XYZ10#define XXXABC - XYZvoid main(){int a;a = XXX * 10;printf("%d\n", a);}
L1.Q2 : Write the output of this program
#include#define calc(a, b)(a * b) / (a - b)void main(){int a = 20, b = 10;printf("%d\n", calc(a + 4, b -2));}
L1.Q3 : What will be output of the following program ?
#includevoid main(){int cnt = 5, a;do {a /= cnt;} while (cnt --);printf ("%d\n", a);
 
}
L1.Q4 : Print the output of this program
#includevoid main(){int a, b, c, abc = 0;a = b = c = 40;if (c) {int abc;abc = a*b+c;}printf ("c = %d, abc = %d\n", c, abc);}
L1.Q5 : Print the output of this program
#includemain(){int k = 5;if (++k < 5 && k++/5 || ++k <= 8);printf("%d\n", k);}
L1.Q6 : What is the output of this program ?
#includevoid fn(int, int);main(){int a = 5;printf("Main : %d %d\n", a++, ++a);fn(a, a++);}
 
void fn(int a, int b){printf("Fn : a = %d \t b = %d\n", a, b);}
Answers
L1.A1Solution forL1.Q1 
a = xxx * 10which is => a = ABC - XYZ * 10=> a = 20 - 10 * 10=> a = 20 - 100=> a = -80
L1.A2Solution forL1.Q2 
Actual substitution is like this :calc(20+4, 10 -2) is calculated as follows(20+4 * 10-2) / (20+4 - 10-2)(20+40-2) / 1258 / 12 = 4.8since it is printed in %d the ans is 4
L1.A3Solution forL1.Q3 
 This problem will compile properly, but it will give runtime error. It will give divide-by-zero error. Look in tothe do loop portiondo { a /= cnt; } while (cnt --);when the 'cnt' value is 1, it is decremented in 'while( cnt --)' and on next reference of 'cnt' it becomes zero.a /= cnt; /* ie. a /= 0 */which leads to divide-by-zero error.
L1.A4Solution forL1.Q4 
the result will be c = 40 and abc = 0;because the scope of the variable 'abc' inside if(c) {.. }

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->