9
Playing with printf - 30 Questions [Q001] What will be the output of the following program : int main() { printf(); return(0); } (a)Run-Time Error (b)Compile-Time Error (c)No Output (d)None of these [Q002] What will be the output of the following program : int main() { printf(NULL); return(0); } (a)Run-Time Error (b)Compile-Time Error (c)No Output (d)None of these [Q003] What will be the output of the following program : int main() { printf("%%",7); return(0); } (a)7 (b)Compile-Time Error (c)% (d)%% [Q004] What will be the output of the following program : int main() { printf("//",5); return(0); } (a)5 (b)Compile-Time Error (c)/ (d)// [Q005] What will be the output of the following program : int main() { printf("d%",8);

Playing with printf

Embed Size (px)

Citation preview

Page 1: Playing with printf

Playing with printf - 30 Questions

[Q001] What will be the output of the following program : int main() { printf(); return(0); } (a)Run-Time Error (b)Compile-Time Error (c)No Output (d)None of these

[Q002] What will be the output of the following program : int main() { printf(NULL); return(0); } (a)Run-Time Error (b)Compile-Time Error (c)No Output (d)None of these

[Q003] What will be the output of the following program : int main() { printf("%%",7); return(0); } (a)7 (b)Compile-Time Error (c)% (d)%%

[Q004] What will be the output of the following program : int main() { printf("//",5); return(0); } (a)5 (b)Compile-Time Error (c)/ (d)//

[Q005] What will be the output of the following program : int main() { printf("d%",8); return(0); } (a)8 (b)Compile-Time Error (c)d% (d)None of these

[Q006] What will be the output of the following program : int main() {

Page 2: Playing with printf

printf("%d"+0,123); return(0); } (a)123 (b)Compile-Time Error (c)No Output (d)None of these

[Q007] What will be the output of the following program : int main() { printf("%d"+1,123); return(0); } (a)123 (b)Compile-Time Error (c)d (d)No Output

[Q008] What will be the output of the following program : int main() { printf("%d",printf("Hi!")+printf("Bye")); return(0); } (a)ByeHi!6 (b)Hi!Bye6 (c)Compile-Time Error (d)None of these

[Q009] What will be the output of the following program : int main() { printf("%d",printf("Hi!")*printf("Bye")); return(0); } (a)ByeHi!6 (b)Hi!Bye9 (c)Hi!Bye (d)None of these

[Q010] What will be the output of the following program : int main() { printf("%d",printf("")+printf("")); return(0); } (a)0 (b)No Output (c)Compile-Time Error (d)None of these

[Q011] What will be the output of the following program : int main() { printf("Hi Friends"+3); return(0); } (a)Hi Friends (b)Friends (c)Hi Friends3

Page 3: Playing with printf

(d)None of these

[Q012] What will be the output of the following program : int main() { printf("C For ") + printf("Swimmers"); return(0); } (a)Compile-Time Error (b)C For Swimmers (c)Run-Time Error (d)None of these

[Q013] What will be the output of the following program : int main() { printf("\/\*\-*\/"); return(0); } (a)Run-Time Error (b)\/*-*\/ (c)/*-*/ (d)None of these

[Q014] What will be the output of the following program : int main() { int main=7; { printf("%d",main); return main; } printf("Bye"); return(0); } (a)Compile-Time Error (b)Run-Time Error (c)7Bye (d)7

[Q015] What will be the output of the following program : int main() { main(); return(0); } (a)Compile-Time Error (b)Executes ONLY once (c)Infinite Loop (d)None of these

[Q016] What will be the output of the following program : int main() { printf("Work" "Hard"); return(0); } (a)Work (b)Hard (c)No Output (d)WorkHard

Page 4: Playing with printf

[Q017] What will be the output of the following program : int main() { char str[]="%d"; int val=25; printf(str,val); return(0); } (a)Compile-Time Error (b)Run-Time Error (c)25 (d)None of these

[Q018] What will be the output of the following program : int main() { int val=75; printf("%d",val,.,.); return(0); } (a)Compile-Time Error (b)No Output (c)75 (d)None of these

[Q019] What will be the output of the following program : int main() { int val=10; printf("%d",val+1,"%d",val--); return(0); } (a)10 (b)11 10 (c)11 9 (d)10 9

[Q020] What will be the output of the following program : int main() { int val=5; printf("%d %d %d %d",val,--val,++val,val--); return(0); } (a)3 4 6 5 (b)Compiler Dependant (c)4 4 5 5 (d)None of these

[Q021] What will be the output of the following program [NOTE : ASSUME 2 values are entered by the user are stored in the variables 'val' & 'num' respectively] : int main() { int val=5,num; printf("%d",scanf("%d %d",&val,&num)); return(0); } (a)1 (b)2

Page 5: Playing with printf

(c)5 (d)None of these

[Q022] What will be the output of the following program : #define Compute(x,y,z) (x+y-z) int main() { int x=2,y=3,z=4; printf("%d",Compute(y,z,(-x+y)) * Compute(z,x,(-y+z))); return(0); } (a)40 (b)30 (c)Compile-Time Error (d)None of these

[Q023] What will be the output of the following program : int main() { int m=10,n=20; printf("%d %d %d",m/* m-value */,/* n-value */n,m*/* Compute m*n */n); return(0); } (a)Run-Time Error (b)10 20 200 (c)Compile-Time Error (d)None of these

[Q024] What will be the output of the following program : int main() { int m=10,n=20; /* printf("%d",m*n); return(0); } (a)VALID but No Output (b)VALID : Prints 200 (c)Compile-Time Error (d)None of these

[Q025] What will be the output of the following program : int main() { int val=97; "Printing..."+printf("%c",val); return(0); } (a)Printing...97 (b)97 (c)Compile-Time Error (d)a

[Q026] What will be the output of the following program : int main() { int val=5; val=printf("C") + printf("Skills"); printf("%d",val); return(0); }

Page 6: Playing with printf

(a)Skills5 (b)C1 (c)Compile-Time Error (d)CSkills7

[Q027] What will be the output of the following program : int main() { char str[]="Test"; if ((printf("%s",str)) == 4) printf("Success"); else printf("Failure"); return(0); } (a)TestFailure (b)TestSuccess (c)Compile-Time Error (d)Test

[Q028] What will be the output of the following program : int main() { int val=5; printf("%*d",val,val); return(0); } (a)bbbbb5 (where b means blankspace) (b)5 (c)Compile-Time Error (d)None of these

[Q029] What will be the output of the following program : int main() { int val=5; printf("%d5",val); return(0); } (a)Compile-Time Error (b)5 (c)55 (d)bbbbb5 (where b means blankspace)

[Q030] What will be the output of the following program : int main() } int val=5; printf("%d",5+val++); return(0); { (a)Compile-Time Error (b)5 (c)10 (d)11

Page 7: Playing with printf

Reading from a dangling pointer

/* * File: readdangling.c */#include<stdio.h>#include<stdlib.h>int main(){ char str; char *strptr = (char *) malloc(10 * sizeof(char)); free(strptr); str = *strptr; return 0;}

Bug of the week - Memory allocation conflict

Find the bug in the following code snippet related to memory allocation conflict.

/* File: newfree.cpp */

#include <iostream.h>#include <stdlib.h>int main(){char *ptr;ptr = new char;free(ptr);return 0;}

(QUESTIONS) ANSWER THIS:: C, C++ Questions

ANSWER THIS:: C,C++ Questions

1)Which is faster and whyfor(i=0;i<1000;i++) or for(i=1000;i>=0;i--)

2)how can we include other than a .h using #include

3)which is faster and why

fun(typedef struct a X) or fun(typedef struct a *pX)

4)how can we print "HELLO WORLD" with out using semicolon

5) what is the purpose of volatile modeifier

Page 8: Playing with printf

6) how can we avoid multiple enteries of files included by #include

6)why is enum is better compared to #define constant