C Programming 1
C Programming 1
Structure:
Your First Program
Preprocessor: interact with
#include <stdio.h>
<stdio h> input/output of your computer
printf("Hello World\n");
return 0;
}
Your First Program
Preprocessor: interact with
#include <stdio.h>
<stdio h> input/output of your computer
return 0;
}
Your First Program
Preprocessor: interact with
#include <stdio.h>
<stdio h> input/output of your computer
return 0;
}
New line character
Your First Program
Preprocessor: interact with
#include <stdio.h>
<stdio h> input/output of your computer
Alphabets
Constants
Digits
Variables Instructions Program
Special
Keywords
Symbols
C Character Set
Alphabets A,B,…,Z, a,b, …,z
Digits 0,1,2,…,9
Special Symbols ~‘@#%^&*()_‐+ =|\{}[]:;“ ’ <>,.?/
Getting Started with C
Constants
Variables
Keywords
The Alphabets,
Alphabets Digits and Symbols properly combined form
Constants, Variables and Keywords
A Constant: A q
quantityy that doesn’t change
g stored at a memoryy
location
A Variable: Simply a name given to the memory location where
a value is stored.
Contents of the variable can be changed
Getting Started with C
Type of C Constant:
Primary: Integer, Real, Character, etc..
Primary
Secondary: Array, Pointer, Structure,….
Secondary
Some Rules:
Integer
g Constants:
* Have at least one digit,
* No decimal point,
* if no sign precedes it is assumed to be positive
* No comma or blanks are allowed
* Range ‐32768
32768 to +32767
Getting Started with C
Some Rules:
Real Constants:
* Have at least one digit,
* must have a decimal point,
p ,
* if no sign precedes it is assumed to be positive
* No comma or blanks are allowed
* In exponential form represents in two parts:
Mantissa is appeared before ‘e’ and exponent after ‘e’
Mantissa can be +ve or –ve
Range ‐3.4e38 to +3.4e38
Character Constants
* either a single alphabet, a digit or a symbol enclosed
within single inverted commas
Getting Started with C
Types of Variables
“A
A quantity which may vary during the program execution is a
variable”
Variable Names: Names given to the memory locations where
different constants are stored
• Particular type
yp of variable can hold onlyy that type
yp of data
• Some rules for constructing Variable names
• Start with a alphabet A…Z, a…z
• Names are case sensitive
• Can contain any combination up to 32 (in standard C)
characters of alphabet,
alphabet numbers
numbers, or underscores
• No commas or blanks are allowed
• No symbols are allowed except underscores ( _ )
Getting Started with C
• In c it is compulsory to declare variables before, to use them
• Using a proper naming conversion is a good programming
practice
• Eg: int averageMarks,
averageMarks totalMarksBySubjects
C Keywords
The reserved
Th d words
d whose
h meaning
i h has already
l d been
b
explained to the C compiler
Getting Started with C
C Instructions
Combine constants,
constants variables and keywords in logical manner
• Type declaration : to declare the type of variables used in a
program
• Input/Output: to perform the function of supplying input data
to a p
program
g and obtainingg the result from it
• Arithmetic: to perform arithmetic operation between
constants and variables
• Control: to control the sequence of execution of various
statements in a program
Getting Started with C
Type declaration
C provides a wide range of types. The most common are