0% found this document useful (0 votes)
33 views23 pages

Introduction to C Programming Basics

It is very informative and easy to use pdf file made to surpass other materials over the internet thankyou

Uploaded by

aaryan2517
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views23 pages

Introduction to C Programming Basics

It is very informative and easy to use pdf file made to surpass other materials over the internet thankyou

Uploaded by

aaryan2517
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

Basics of ‘C’

NIT JALANDHAR
low level or high level?

 A low level language is machine dependent


 High level language is computer independent
and translated into computer understandable
code by a compiler
Some Languages by
Paradigm
 Imperative (also called Structured or
Procedural) Programming
 FORTRAN, BASIC, COBOL, Pascal, C
 Object-Oriented Programming
 SmallTalk, C++, Java
 Functional Programming
 LISP, ML, Haskell
History of Languages

 1950s to 1960s
 FORTRAN, COBOL, LISP, BASIC
 1960s to 1970s
 (ALGOL-based) Pascal and others
 1970s to 1980s
 Prolog, C, Ada
 1980s to 1990s
 C++, ML, Perl, Java
Paradigm Change

 Forexample, from Procedural to Object-


Oriented Programming
 Arises
from problems encountered in one
paradigm but addressed in another
 Case study: from C to C++
 Evolution from procedural, to modular, to
object-based, to object-oriented programming
BASIC C CODE

 #include<stdio.h>
 int main()
 {
 printf(“Hello World”);
 return 0;
 }
THE PROCESS OF
COMPILATION
PREPROCESSING

 Remove comments from code


 Include header files in the code
 Substitute values of macros
Compilation

 Compiler generates assembly code


 Assembler converts generated code into binary
code or machine language
 This is also known as object code
LINKER

 Merge all object codes into single one


 In case we are using any library functions,
linker will link our code with those libraries
 Can be static or dynamic
 Generates .exe file
General Aspect of ‘C’

• C WAS ORIGINALLY DEVELOPED IN THE 1970S, BY


DENNIS RITCHIE AT BELL TELEPHONE
LABORATORIES, INC.
• C IS A HIGH LEVEL , GENERAL –PURPOSE
STRUCTURED PROGRAMMING LANGUAGE.
• INSTRUCTIONS OF C CONSISTS OF TERMS THAT
ARE VERY CLOSELY SAME TO ALGEBRAIC
EXPRESSIONS, CONSISTING OF CERTAIN ENGLISH
KEYWORDS SUCH AS IF, ELSE, FOR ,DO AND
WHILE
The Character set of ‘C’
• C LANGUAGE CONSIST OF SOME CHARACTERS
SET, NUMBERS AND
• SOME SPECIAL SYMBOLS. THE CHARACTER SET
OF C CONSIST OF ALL THE ALPHABETS OF
ENGLISH LANGUAGE.
• SPECIAL SYMBOLS {,},[,],?,+,-,*,/,%,!,;,AND
MORE
• 1) IDENTIFIERS 2)KEYWORDS
3)CONSTANTS
• 4) OPERATORS 5)PUNCTUATION SYMBOLS
Identifiers
 A 'C' program consist of two types of elements ,
user defined and system defined. Idetifiers is
nothing but a name given to these elements.
 An identifier is a word used by a programmer to
name a variable , function, or label.
 identifiers consist of letters and digits, in any
order, except that the first character or lable.
 Identifiers consist of letters and digits if any
order,except that the first character must be
letter.
 Both Upper and lowercase letters can be used
Keywords
 Keywords are nothing but auto double int struct
system defined identifiers.
 break else long switch
Keywords are reserved
words of the language.
case enum register typedef
 They have specific
meaning in the language char extern return union
and cannot be used by the
programmer as variable or const float short unsigned
constant names
 C is case senitive, it means continue for signed void
these must be used as it is
default goto sizeof volatile
 32 Keywords in C
Programming
do if static while
Variables
 A variable is nothing but a name given to a storage area that our
programs can manipulate. Each variable in C has a specific type,
which determines the size and layout of the variable's memory;
the range of values that can be stored within that memory; and
the set of operations that can be applied to the variable.
 The name of a variable can be composed of letters, digits, and the
underscore character. It must begin with either a letter or an
underscore. Upper and lowercase letters are distinct because C is
case-sensitive. There are following basic variable types −
Type Description
 char Typically a single octet(one byte). This is an
integer type.
 int The most natural size of integer for the machine.
 float A single-precision floating point value.
 double A double-precision floating point value.
 void Represents the absence of type.
Constants

 A constant is a value or an identifier whose value


cannot be altered in a program. For example: 1, 2.5,
 As mentioned, an identifier also can be defined as a
constant. eg. const double PI = 3.14
 Here, PI is a constant. Basically what it means is that,
PI and 3.14 is same for this program.

Integer constants
 A integer constant is a numeric constant (associated
with number) without any fractional or exponential
part. There are three types of integer constants in C
programming:

 decimal constant(base 10)


 octal constant(base 8)
 hexadecimal constant(base 16)
Constants

Floating-point constants
 A floating point constant is a numeric constant
that has either a fractional form or an exponent
form. For example: 2.0,0.0000234,-0.22E-5

Character constants
 A character constant is a constant which uses
single quotation around characters. For example:
'a', 'l', 'm', 'F'

String constants
 String constants are the constants which are
enclosed in a pair of double-quote marks. For
example: "good" ,"x","Earth is round\n"
Escape Sequences
Sometimes, it is necessary to use characters which cannot be typed or
has special meaning in C programming. For example: newline(enter),
tab, question mark etc. In order to use these characters, escape
sequence is used.
 For example: \n is used for newline. The backslash ( \ ) causes
"escape" from the normal way the characters are interpreted by the
[Link]
Sequences Character
 \b Backspace
 \f Form feed
 \n Newline
 \r Return
 \t Horizontal tab
 \v Vertical tab
 \\ Backslash
 \' Single quotation mark
 \" Double quotation mark
 \? Question mark
 \0 Null character
Operators in C:An operator is a symbol which
operates on a value or a variable. For example: + is an operator to
perform addition.

C programming has wide range of operators to


perform various operations. For better
understanding of operators, these operators can
be classified as:
 Arithmetic Operators
 Increment and Decrement Operators
 Assignment Operators
 Relational Operators
 Logical Operators
 Conditional Operators
 Bitwise Operators
 Special Operators
Arithmetic Operator

 Operator Meaning of Operator


 + addition or unary plus
 - subtraction or unary minus
 * multiplication
 / division
 % remainder after
division( modulo division)
Increment and Decrement
Operators

1. C programming has two operators


increment ++ and decrement -- to
change the value of an operand
(constant or variable) by 1.
2. Increment ++ increases the value by
1 whereas decrement -- decreases the
value by 1.
3. These two operators are unary
operators, meaning they only operate
on a single operand.
eg. int a=10, b=100
++a = 11
--b = 99
C Assignment Operators
 An assignment operator is used for
assigning a value to a variable. The most
common assignment operator is =
 Operator Example Same as
= a=b a=b
 += a += b a = a+b
 -= a -= b a = a-b
 *= a *= b a = a*b
 /= a /= b a = a/b
 %= a %= b a = a%b
C Relational Operators
 A relational operator checks the relationship
between two operands. If the relation is true, it
returns 1; if the relation is false, it returns value
0.
 Relational operators are used in decision making
and loops.
Operator Meaning of Operator Example
 == Equal to 5 == 3 returns 0
 > Greater than 5 > 3 returns 1
 < Less than 5 < 3 returns 0
 != Not equal to 5 != 3 returns 1
 >= Greater than or equal to 5 >= 3
returns 1
 <= Less than or equal to 5 <= 3 return 0

You might also like