Anda di halaman 1dari 129
Contents Introduction 1 Declarations and Initialization 2 Control instructions 3 Expressions 4 Flcating Point Issues 5 Punctions 6 TheC Preprocessor 7 Pointers 8 More About Pointers 9 Amays 10 Strings 11 Structure, Unions and Emumerations 12 InpuvOupet 13 Command Line Arguments 14 Bitwise Operators 1S Subsleties of »pedef 16 ‘The const Phenomenon 17 Memory Allocation 18 Variable Number of Arguments 19 Complicated Dectarations 20. Library Functions wi " n 37 47 35 @ 31 107 129 141 157 169 119 189 227 237 Introduction “There is no dearth of good C programming books in the marke. However, I found that there is not much material which could help a CC programmer to test his prograrnming strengths, help improve his ‘confidence and inthe process hone his C skills. Hence this book: ‘This is not text book on C. Infact its ar from it. Itcontains a lot of questions sogregated topic-wise according to my perception ofthe language. Almost all the questions are real one's tsked 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 inthis 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 oF using C-and you hhave questions about C that area’ answered in 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 an the C language. Also it doesn't cover every aspect ofevery operating system under which Cis running, 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 t0 the ‘Questions in that chapter. You would find some answers more laborate than others. At first sight this may seem unnecessary. However, Ihave done this to give you the complete picture rather than oversimplifying or leaving out important detail. Ihave tie to avoid the questions whose answers ate most obyious because te dea was not fo inerease the numberof questions, bt to presen questions which would force the readers to think tice before asivering, Thats tune withthe pit of C- be precise, brevity has its own importance So rll your sleeves and get on with the real questions. Good vc! Yashavant P. Kanetkar Nov., 1996 Chapter 1 Declarations and Initializations Qu What would be the ouput ofthe following program? 1 charfor 1,02 print (Sed ua ast), abe (2)) ] Q 2 What would be the output ofthe following program? inux=<0. rain) ints 20: rit (rex): Q 2 What would be the output ofthe f lowing program? main() ( int=40; vx =20: pri Wa" x); ) ae Qu Is the following statement «declaration ora definition? center int Qs ‘What would be the output ofthe following program? rman) { ext it; 120; print Seize ()) 4 Would vary from compiler to compiler Error, undefined powp Isittrcthata global variable may have several declarations, but only ‘one definition? Qu Is tare that function may have several declarations, bu only one Aefinition? Qs Inthe following program where is the variable « getting defined and, where is it petting declared? rin) i exemirta; Pit (St); ima=20; Q 19 ‘What would be the output of the following program? man) 4 tom nt a; i ("ask ) fta=29

Anda mungkin juga menyukai