You are on page 1of 129
Contents Introduction 1 Declarations and Initslzations 2 Control Instructions 3 Expressions 4 Floating Point Issues 5 Functions 6 TheC Preprocessor 7 Pointers 8 More About Pointers 9 Amys 10 Strings 11 Structures, Unions and Emumeraions 12 TapowOurput 13 Command Line Arguments 14 Bitwise Operators 1S Sublets of npedef 16 ‘The const Phenomenon 17 Memory Allocation 18 Variable Number of Arguments 19 Complicated Declarations 20. Library Functions wi " n 37 47 35 31 107 129 141 157 169 179 139 227 237 Introduction “There is no dearth of good C programming books in the marke However, found that there is not much material which could help a C progratnmer to test his programming strengths, help improve his ‘confidence and inthe process hone his C skills. Hence this book: ‘This is not text book on C. Infact itis far from it. Iccontains a lot of questions sogregated topic-wise according to my perception ofthe language. Almost all the questions are real one's eked by real people sttempiing to learn or program in C “There is no reason why you should read the questions in the same order as they appear in this book. Youcan pick up any topic that you think you are good at (or poor at) and tr to test your skills on that topic. “There is a good chance that i you ae learning or using C-and you hhave questions about C that area’ tansweredin any of the other books {you've checked, you would find them answered here. twould be 109 much to expect that you would find in this book answer to every ‘question you would have when you're programming in C. Ths is [because many ofthe questions that may come up in your program: ‘ming would have todo with your problem domain, whereas this book Concentrates only on the C language. Also it doesn't cover every aspect of every operating systemunder which Cis nning, Problems specific to an operating systems, and general-purpose algorithms are properly discussed in books devoted to those topics. ‘At the end of each chapter you would find correct answers 0 the ‘questions in that chapter. You would find some answers more laborate than others. At first sight this may seem unnecessary. However, I have done this to give you the complete picture rather than oversimplifying or leaving out important detail have tried to avoid the questions whese answers are most obvious because te dea was not fo inrease the numberof questions, bt to presen questions which would force the readers to think vice before answering, Thatsin tune withthe spit of C- be precise, brevity has its own importance. So rll your sleeves and get on with the real questions. Good ck! Yashavant P. Kanetkar Nov., 1996 Chapter 1 Declarations and Initializations Qu What would be the output ofthe folowing progratn? 1 charfr 1,02 Print (Se a, aot (et), zoo (2)) } Q 2 What would be the output ofthe following program? invx=40 main) ints =20: rit (nex): Q we ‘What would be the output ofthe following program? ‘Test Your C Skills main() ( intx=40; vx =20: pri Wt" x); ) eek Qa Is the following statement a declaration ora definition? center int Qs ‘What would be the output ofthe following program? rman) { ext it i420; Print Se, sizet (1) 4 Would vary from compiler to compiler Error, undefined poe Isittructhata global variable may have several declarations, but only ‘one definition? Qu Is ittrve that a function may have several declarations, but only one definition? Q is Inthe following program where is the variable « getting defined and, where is it petting declared? af extmicta; int ("a ; ima=20; Q 19 ‘What would be the ourpu ofthe following program? man) ( tom eta; i ("ask ) fta=20;

You might also like