×
A DAY WITHOUT LEARNING IS A DAY WASTED
--Your friends at LectureNotes
Close

Note for Programming in C - C By Anas Khan

  • Programming in C - C
  • Note
  • LAXMI NARAYAN COLLEGE OF TECNOLOGY GWALIOR - LNCT
  • Computer Science Engineering
  • 93 Views
  • Uploaded 4 months ago
Anas Khan
Anas Khan
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-1

C Programming Tutorial

Text from page-2

Table of Contents C Language Overview .............................................................. 1 Facts about C ............................................................................................... 1 Why to use C ? ............................................................................................. 2 C Programs .................................................................................................. 2 C Environment Setup ............................................................... 3 Text Editor ................................................................................................... 3 The C Compiler ............................................................................................ 3 Installation on Unix/Linux ............................................................................. 4 Installation on Mac OS .................................................................................. 4 Installation on Windows ............................................................................... 4 C Program Structure ................................................................ 5 C Hello World Example ................................................................................. 5 Compile & Execute C Program ....................................................................... 6 C Basic Syntax ......................................................................... 7 Tokens in C .................................................................................................. 7 Semicolons ; ................................................................................................ 7 Comments ................................................................................................... 8 Identifiers .................................................................................................... 8 Keywords .................................................................................................... 8 Whitespace in C ........................................................................................... 9 C Data Types ......................................................................... 10 Integer Types ............................................................................................. 10 Floating-Point Types ................................................................................... 11 The void Type ............................................................................................ 12 C Variables ............................................................................ 13 Variable Declaration in C ................................Error! Bookmark not defined. Variable Initialization in C ...............................Error! Bookmark not defined. Lvalues and Rvalues in C ............................................................................. 15 C Constants and Literals ........................................................ 17 Integer literals............................................................................................ 17 Floating-point literals.................................................................................. 18 Character constants.................................................................................... 18 iii

Text from page-3

String literals.............................................................................................. 19 Defining Constants ..................................................................................... 19 The #define Preprocessor ...................................................................... 19 The const Keyword ................................................................................. 20 C Storage Classes ................................................................. 22 The auto Storage Class ................................................................................ 22 The register Storage Class ........................................................................... 22 The static Storage Class............................................................................... 23 The extern Storage Class ............................................................................. 24 C Operators ........................................................................... 25 Arithmetic Operators .................................................................................. 25 Relational Operators................................................................................... 26 Logical Operators ....................................................................................... 28 Bitwise Operators....................................................................................... 29 Assignment Operators ................................................................................ 31 Misc Operators ↦ sizeof & ternary .............................................................. 33 Operators Precedence in C .......................................................................... 33 Decision Making in C.............................................................. 35 if statement ............................................................................................... 36 Syntax ..................................................................................................... 36 Flow Diagram .......................................................................................... 36 Example .................................................................................................. 36 if...else statement ...................................................................................... 37 Syntax ..................................................................................................... 37 Flow Diagram .......................................................................................... 38 Example .................................................................................................. 38 The if...else if...else Statement ..................................................................... 39 Syntax ..................................................................................................... 39 Example .................................................................................................. 39 Nested if statements .................................................................................. 40 Syntax ..................................................................................................... 40 Example .................................................................................................. 40 switch statement ....................................................................................... 41 Syntax ..................................................................................................... 41 Flow Diagram .......................................................................................... 42 Example .................................................................................................. 42 Nested switch statements ........................................................................... 43 Syntax ..................................................................................................... 43 Example .................................................................................................. 43 iii

Text from page-4

The ? : Operator ......................................................................................... 44 C Loops.................................................................................. 45 while loop in C ........................................................................................... 46 Syntax ..................................................................................................... 46 Flow Diagram .......................................................................................... 46 Example .................................................................................................. 47 for loop in C ............................................................................................... 47 Syntax ..................................................................................................... 47 Flow Diagram .......................................................................................... 48 Example .................................................................................................. 48 do...while loop in C ..................................................................................... 49 Syntax ..................................................................................................... 49 Flow Diagram .......................................................................................... 50 Example .................................................................................................. 50 nested loops in C ........................................................................................ 51 Syntax ..................................................................................................... 51 Example .................................................................................................. 52 break statement in C .................................................................................. 53 Syntax ..................................................................................................... 53 Flow Diagram .......................................................................................... 53 Example .................................................................................................. 54 continue statement in C .............................................................................. 54 Syntax ..................................................................................................... 54 Flow Diagram .......................................................................................... 55 Example .................................................................................................. 55 goto statement in C .................................................................................... 56 Syntax ..................................................................................................... 56 Flow Diagram .......................................................................................... 56 Example .................................................................................................. 57 The Infinite Loop ........................................................................................ 57 C Functions ............................................................................ 59 Defining a Function .................................................................................... 59 Example .................................................................................................. 60 Function Declarations ................................................................................. 60 Calling a Function ....................................................................................... 60 Function Arguments ................................................................................... 61 Function call by value ............................................................................. 62 Function call by reference ....................................................................... 63 C Scope Rules ....................................................................... 65 iii

Lecture Notes