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

05 - c-puzzles

Ratings: (0)|Views: 98|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

 
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);}solution for l1.q1-80--------------------------------------------------------------------------------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));}solution for l1.q24--------------------------------------------------------------------------------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);}solution for l1.q3--------------------------------------------------------------------------------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);}solution for l1.q4--------------------------------------------------------------------------------l1.q5 : print the output of this program#includemain(){int k = 5;if (++k < 5 && k++/5 || ++k <= 8);printf("%d\n", k);}solution for l1.q5--------------------------------------------------------------------------------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);}
 
solution for l1.q6--------------------------------------------------------------------------------answersl1.a1solution for l1.q1a = xxx * 10which is => a = abc - xyz * 10=> a = 20 - 10 * 10=> a = 20 - 100=> a = -80--------------------------------------------------------------------------------l1.a2solution for l1.q2actual 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 for l1.q3this 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 for l1.q4the result will be c = 40 and abc = 0;because the scope of the variable 'abc' inside if(c) {.. }is not valid out side that if (.) { .. }.--------------------------------------------------------------------------------

You're Reading a Free Preview

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