C Programming: Ganesan Chandrasekaran #51450717
C Programming: Ganesan Chandrasekaran #51450717
11/16/2019
1
HCL Technologies
TEST
Use
include the
use one header file preprocessor
How to restrict the header files to be included only once header file
1 Use only onec to include all other derivatives
in the program ? using double
header files. conditioning to
quotes
include
Limited
What is kind of memory damage is happening due to
3 Memory leak Truncation Fragmentation memory
malloc()
allocation
11/16/2019
2
HCL Technologies
HISTORY OF C PROGRAMMING
• Invented and Implemented by Dennis Ritchie in 1972 at AT&T Bell
Laboratory on DEC PDP-11 under UNIX platform from BCPL.
• ANSI – 1989 to 1990 [C89]
• ANSI/ISO
• Amendment 1 in 1995 to C, becomes base document for Standard C++
and defines the C subset of C++
• A Middle Level Language - MLL (since it combines the control of LLL Dennis M Ritchie
language and flexibility of HLL)
• A portable Language
DEC PDP-11
11/16/2019
3
HCL Technologies
BRIEF OF C
• It supports basic data types [integer, character, floating point]
• It allows direct manipulations of bits, bytes and word and memory (pointer) and it makes it to do
system-level Programming.
11/16/2019
4
HCL Technologies
ADVANTAGE OF C
• It is structured Language not block-structured
• It allows several looping methods and almost avoids goto statement.
• Modular programming ability – Sub-routines
• Code-Block – placing code inside a block.
• Complier , not an Interpreter
11/16/2019
5
HCL Technologies
C KEYWORDS
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while
11/16/2019
6
HCL Technologies
GENERAL FORM OF C PROGRAMMING
Pre
processor
derivative
Structure &
Union
Declarations
Global Variable
declarations
Sub-Function Declarations
Sub-Function definitions
11/16/2019
7
HCL Technologies
PRE-PROCESSOR DERIVATIVES
• Starts with ‘#’ symbol
• Not required ‘;’ at the end of the statement
• One line statement can be extended by ‘\’
• Used to execute certain codes before compiling.
• Can be used to decide the environment of complier
11/16/2019
8
HCL Technologies
SOME DERIVATIVES
• #include -> includes any file to the source code
• #ifdef & #ifndef
• #if - #else -#endif
• #define
• #pragma
auto_inline, comment, once, etc
for more: http://msdn.microsoft.com/en-us/library/d9x1s805.aspx
11/16/2019
9
HCL Technologies
I/O STATEMENTS
Formatted an un-formatted Statements
Un-Formatted:
10
11/16/2019
HCL Technologies
VARIABLES
What is variable?
• Standard, Build-in
Standard: integer, character, floating point
Build-in: double, pointers, structure, union
Declaration
<storage class> <type modifier> <data type> [variable name];
11
11/16/2019
HCL Technologies
STORAGE CLASS AND SCOPE
Defines the life time of the variable:
1. auto
2. static
3. register
4. extern
Files are Global scope
12
11/16/2019
HCL Technologies
TYPE MODIFIER
Modifies the basic character of the data type
Sign modifiers
• signed
• unsigned
length modifiers
• long
• short
13
11/16/2019
HCL Technologies
ARITHMETIC AND LOGIC
Constants, Expressions
Arithmetic, Relational & Logic Operators
+, -, *, /, %
<, >, <=, >=, !, !=
|, &, !, ||, &&, ^, ~, <<, >>
Increment & decrement
++, --
Post and Pre increment & decrement
14
11/16/2019
HCL Technologies
CONDITIONAL STATEMENTS
• If
• If-else
• If-else if
• Nested if
• Switch-case
• What is mean by if(1) and if (0)?
15
11/16/2019
HCL Technologies