9788192107530 Flipbook PDF


110 downloads 116 Views 8MB Size

Recommend Stories


Porque. PDF Created with deskpdf PDF Writer - Trial ::
Porque tu hogar empieza desde adentro. www.avilainteriores.com PDF Created with deskPDF PDF Writer - Trial :: http://www.docudesk.com Avila Interi

EMPRESAS HEADHUNTERS CHILE PDF
Get Instant Access to eBook Empresas Headhunters Chile PDF at Our Huge Library EMPRESAS HEADHUNTERS CHILE PDF ==> Download: EMPRESAS HEADHUNTERS CHIL

Story Transcript

The Ultimate

C Dr R Nageswara Rao CONCEPTS

PROGRAMS

INTERVIEW QUESTIONS

Copyright

©

by

All rights reserved.

Copyright ©2012 Career Monk Publications. All rights reserved. All rights reserved. No part of this book may be reproduced in any form or by any electronic or mechanical means, including information storage and retrieval systems, without written permission from the publisher or author.

This book is fondly dedicated to my children and .

About the Author writing this book is not only to teach C but also make the student successful in the Campus and Off-campus interviews. Dr R Nageswara Rao is associated with teaching Computer Science since 1993. He has worked at various colleges as Head of the Department, Dept of Computers and as a freelance developer for some time for a couple of organizations. He taught C and C++ till the year 2004 and since then more involved in teaching Java. Since 1998, Mr Rao was on the editorial board of Computer Vignanam, a widely circulated monthly magazine published in Telugu. He wrote several articles on C, C++ and Java including articles on Virtual Reality, Mobile applications, Blue tooth technology and Global positioning systems. His dedication in teaching is continuing to attract thousands of students from various Indian Universities in addition to students from foreign countries.

Contents at a Glance 1. Fundamental Concepts in C ------------------------------------------------------- 21 2. Data types and OPERATORS --------------------------------------------------------- 45 3. Control Statements in C ----------------------------------------------------------- 68 4. Arrays ---------------------------------------------------------------------------------- 99 5. Functions --------------------------------------------------------------------------- 121 6. Characters and Strings ----------------------------------------------------------- 148 7. Storage Classes -------------------------------------------------------------------- 169 8. Pointers ------------------------------------------------------------------------------ 179 9. Structures and Unions------------------------------------------------------------ 220 10. File Concepts ----------------------------------------------------------------------- 244 11. Command Line Arguments ------------------------------------------------------- 274 12. Macros and Enumerations ------------------------------------------------------- 291 13. Data Structures in C -------------------------------------------------------------- 300 14. Searching, Sorting and Merging ------------------------------------------------- 337 15. Graphics And Animation --------------------------------------------------------- 356 Appendix-I Interview Question Index ---------------------------------------------- 395 Appendix-II Program Index ----------------------------------------------------------- 401

Table of Contents 1. Fundamental Concepts in C ------------------------------------------------------- 21 The birth of C ------------------------------------------------------------------------ 22 Composition of a C program ------------------------------------------------------ 22 Character set in C ------------------------------------------------------------------ 22 Words in C --------------------------------------------------------------------------- 22 C Statements ------------------------------------------------------------------------ 24 Format specifiers in printf() ------------------------------------------------------- 32 Execution of a C program --------------------------------------------------------- 32 Executing the C program in Turbo C -------------------------------------------- 34 Getting help on C in Turbo C ----------------------------------------------------- 36 Tracing the C program step by step --------------------------------------------- 38 Executing the C program in UNIX ----------------------------------------------- 38 Executing the C program in Microsoft Visual Studio ------------------------- 39 Executing a C program with command line arguments ---------------------- 43

2. Data types and Operators ---------------------------------------------------------- 45 Datatypes in C----------------------------------------------------------------------- 46 Primary datatypes ------------------------------------------------------------------ 47 Modifiers------------------------------------------------------------------------------ 49 Finding the maximum/minimum values of datatypes ----------------------- 50 Qualifiers ----------------------------------------------------------------------------- 51 Operators in C ----------------------------------------------------------------------- 52

3. Control Statements in c ------------------------------------------------------------ 68 Sequential execution --------------------------------------------------------------- 68 Random execution ------------------------------------------------------------------ 69 ------------------------------------------------------------------- 70 ----------------------------------------------------------------------- 73 while loop ---------------------------------------------------------------------------- 74 for loop -------------------------------------------------------------------------------- 77 switch statement -------------------------------------------------------------------- 83

clrscr() -------------------------------------------------------------------------------- 84 gotoxy() ------------------------------------------------------------------------------- 85 getche() ------------------------------------------------------------------------------- 85 break statement -------------------------------------------------------------------- 87 continue statement ---------------------------------------------------------------- 89 goto statement ---------------------------------------------------------------------- 90 return statement ------------------------------------------------------------------- 92

4. Arrays --------------------------------------------------------------------------------- 99 Single dimensional arrays or 1D arrays --------------------------------------- 100 Creating a 1D array --------------------------------------------------------------- 100 Why the array index starts with zero? ----------------------------------------- 102 Two dimensional arrays ---------------------------------------------------------- 109 Creating 2D arrays ---------------------------------------------------------------- 110 Three dimensional arrays -------------------------------------------------------- 117 Creating 3D arrays ---------------------------------------------------------------- 118

5. Functions ---------------------------------------------------------------------------- 121 Parts of a function ---------------------------------------------------------------- 122 Different ways of writing a function -------------------------------------------- 125 Calling a function ----------------------------------------------------------------- 128 Where to write a function -------------------------------------------------------- 128 function definition ---------------------------------------------------------------- 128 Formal arguments and actual arguments ------------------------------------ 132 Passing arrays to functions ----------------------------------------------------- 132 Recursive function ---------------------------------------------------------------- 138 Scope of variables in a function ------------------------------------------------ 140 Structured programming -------------------------------------------------------- 141 Creating our own header files --------------------------------------------------- 144

6. Characters and Strings ----------------------------------------------------------- 148 Handling characters -------------------------------------------------------------- 148 Character testing functions ----------------------------------------------------- 151 Strings ------------------------------------------------------------------------------ 153 Storage of strings in memory---------------------------------------------------- 155 String handling functions ------------------------------------------------------- 156

strlen() ------------------------------------------------------------------------------ 157 strcpy() and strncpy() ------------------------------------------------------------- 158 strcat() ------------------------------------------------------------------------------ 158 strcmp() and stricmp()------------------------------------------------------------ 160 strncmp() and strnicmp() -------------------------------------------------------- 161 strupr() and strlwr()--------------------------------------------------------------- 161 strrev() ------------------------------------------------------------------------------ 162 strchr() ------------------------------------------------------------------------------ 163 strstr()------------------------------------------------------------------------------- 164 Passing strings to functions----------------------------------------------------- 165

7. Storage Classes -------------------------------------------------------------------- 169 Automatic storage class --------------------------------------------------------- 170 Register storage class ------------------------------------------------------------ 171 Static storage class --------------------------------------------------------------- 172 External storage class ------------------------------------------------------------ 174 Local variables--------------------------------------------------------------------- 177

8. Pointers ------------------------------------------------------------------------------ 179 Pointer arithmetic ----------------------------------------------------------------- 182 Arrays and pointers -------------------------------------------------------------- 185 Dynamic memory allocation ---------------------------------------------------- 191 Difference between static and dynamic memory ---------------------------- 193 malloc() ----------------------------------------------------------------------------- 195 realloc() ----------------------------------------------------------------------------- 196 calloc() ------------------------------------------------------------------------------ 196 free() --------------------------------------------------------------------------------- 196 Array of pointers ------------------------------------------------------------------ 198 Functions accepting and returning pointers --------------------------------- 201 Function pointers ----------------------------------------------------------------- 207 Callback mechanism ------------------------------------------------------------- 209 Dangling pointers ----------------------------------------------------------------- 212 Null pointers ----------------------------------------------------------------------- 212 Wild pointers ---------------------------------------------------------------------- 213 Near, far and huge pointers ----------------------------------------------------- 214

Generic pointer or void pointer ------------------------------------------------- 215 Size of a pointer ------------------------------------------------------------------- 216 Pointers to pointers --------------------------------------------------------------- 217 Advantages and disadvantages of pointers ----------------------------------- 219

9. Structures and Unions ------------------------------------------------------------ 220 Accessing structure elements --------------------------------------------------- 221 Declaring and initializing the structure --------------------------------------- 221 Structure pointer ------------------------------------------------------------------ 223 Array of structures ---------------------------------------------------------------- 224 Array of pointers to structures -------------------------------------------------- 230 Passing structures to functions ------------------------------------------------ 232 Copying structure variables ----------------------------------------------------- 235 Nested structures ----------------------------------------------------------------- 237 UNIONS ----------------------------------------------------------------------------- 240

10. File Concepts ----------------------------------------------------------------------- 244 Opening a file ---------------------------------------------------------------------- 245 Closing a file ----------------------------------------------------------------------- 247 Types of files ----------------------------------------------------------------------- 247 Differences between text files and binary files ------------------------------- 248 Text files with characters -------------------------------------------------------- 249 Text files with strings ------------------------------------------------------------- 251 Formatted text files --------------------------------------------------------------- 254 Binary files ------------------------------------------------------------------------- 258 Sending program output to printer -------------------------------------------- 262 Storing the program output in another file ----------------------------------- 262 Random accessing of files ------------------------------------------------------- 264 Knowing the file size and number of records in the file -------------------- 265 Record updation ------------------------------------------------------------------- 267 Record deletion -------------------------------------------------------------------- 270 Knowing the files in a directory ------------------------------------------------- 272

11. Command Line Arguments ------------------------------------------------------- 274 main() without any parameters ------------------------------------------------- 275 main() with void type parameter ------------------------------------------------ 275

main() with two parameters ----------------------------------------------------- 276 main() with three parameters --------------------------------------------------- 277 Executing code after main() is exited ------------------------------------------ 281 Calling another program from main() ------------------------------------------ 282 Uses of command line arguments ---------------------------------------------- 284 Displaying file contents Copying file contents Deleting a file

show command ------------------------------------ 284

cpy command ----------------------------------------- 286

destroy command --------------------------------------------- 287

Refreshing the screen

fresh command -------------------------------------- 288

Counting chars, words and lines

count command ------------------------ 289

12. Macros and Enumerations ------------------------------------------------------- 291 Macros ------------------------------------------------------------------------------ 293 Conditional compilation --------------------------------------------------------- 294 Enumerations --------------------------------------------------------------------- 296

13. Data Structures in C -------------------------------------------------------------- 300 Stacks ------------------------------------------------------------------------------- 301 Creating a stack ------------------------------------------------------------------- 302 Push operation -------------------------------------------------------------------- 302 Pop operation ---------------------------------------------------------------------- 302 Using stack to validate an expression ----------------------------------------- 306 Queues ----------------------------------------------------------------------------- 308 Creating a queue ------------------------------------------------------------------ 309 Inserting an element into queue ----------------------------------------------- 309 Deleting an element from the queue ------------------------------------------- 309 Circular queues ------------------------------------------------------------------- 313 Linked lists ------------------------------------------------------------------------- 316 Creating a linked list ------------------------------------------------------------- 318 Displaying the linked list -------------------------------------------------------- 318 Inserting new node in the beginning of the list ------------------------------ 320 Inserting new node at the end of the list -------------------------------------- 323 Inserting new node in the middle of the list ---------------------------------- 323 Deleting starting node from the list -------------------------------------------- 325 Deleting the last node from the list -------------------------------------------- 327

Deleting a node from the middle of the list ----------------------------------- 327 Doubly linked list ----------------------------------------------------------------- 328 Creating a doubly linked list ---------------------------------------------------- 329 Traversal in a doubly linked list ------------------------------------------------ 330 Forward traversal ----------------------------------------------------------------- 330 Backward traversal --------------------------------------------------------------- 330 Inserting node at the beginning of doubly linked list ----------------------- 332 Inserting node after a specific location in the doubly linked list ---------- 333 Removing the beginning node from doubly linked list ---------------------- 335 Removing a node from a specific location in the doubly linked list ------- 335

14. Searching, Sorting and Merging ------------------------------------------------- 337 Searching techniques------------------------------------------------------------- 338 Linear search or Sequential search -------------------------------------------- 338 The big O notation ---------------------------------------------------------------- 339 Binary search ---------------------------------------------------------------------- 340 Sorting techniques ---------------------------------------------------------------- 343 Bubble sort ------------------------------------------------------------------------- 343 Quick sort or Partition exchange sort ----------------------------------------- 345 Selection sort ---------------------------------------------------------------------- 350 Insertion sort ---------------------------------------------------------------------- 351 Merging ----------------------------------------------------------------------------- 353

15. Graphics And Animation---------------------------------------------------------- 356 Drawing pixels --------------------------------------------------------------------- 358 Drawing circles -------------------------------------------------------------------- 362 Drawing lines ---------------------------------------------------------------------- 363 Drawing rectangles and squares ----------------------------------------------- 364 Drawing ellipses ------------------------------------------------------------------- 365 Drawing arcs ----------------------------------------------------------------------- 367 Drawing pieslices ------------------------------------------------------------------ 367 Drawing polygons ----------------------------------------------------------------- 368 Foreground and background colors -------------------------------------------- 369 Filling the shapes with colors --------------------------------------------------- 369 Using fonts ------------------------------------------------------------------------- 373

Using mouse in graphics -------------------------------------------------------- 375 Creating GUI components ------------------------------------------------------- 380 Creating Menus ------------------------------------------------------------------- 382 Copying images ------------------------------------------------------------------- 386 Animation of images -------------------------------------------------------------- 388 Playing sound --------------------------------------------------------------------- 393

16. Question Index --------------------------------------------------------------------- 395 Important Interview Questions Index------------------------------------------ 395

17. Program Index ---------------------------------------------------------------------- 401 Chapterwise Program Index ----------------------------------------------------- 401

Get in touch

Social

© Copyright 2013 - 2024 MYDOKUMENT.COM - All rights reserved.