C Programming Concepts
C Programming Concepts
Concepts
CHARACTERISTICS OF AN ALGORITHM
step 1: start
step 2: Read radius
step 3: area=3.142* radius* radius
step 4: print “Area of a circle =“, area
step 5: stop
Introduction to C
Programming
C is a high level programming language developed at AT & T’s
Bell Lab of USA in 1972.
Evolved by Dennis Ritchie from two previous programming
languages, BCPL and B
Originally develop to write UNIX Operating System.
Hardware independent (portable)
C is a structured programming language.
C-LANGUAGE CHARACTER
SET
Among the characters that a programmer can use are the following:
Declaration:
data_ type variable_name;
Eg: int age;
preprocessor statements
global declaration;
main()
{
declaration;
statements;
}
user-defined functions
A SIMPLE C PROGRAM
#include <stdio.h>
main ()
{
/* printing message */
printf (“Introduction to C-Language\n”);
}
C-Tokens
Keywords: All keywords are basically the sequence of character
that have fixed meaning.
Eg: auto, case, char, break, int, for, if, else etc.
Identifiers: Identifiers are the names given to the program
elements such as variables, arrays and functions.
Constants: Two types of constants in C:
Numeric Constant
Integer Constant
Floating-point Constant
Non-numeric Constant
Character Constant
String Constant
Special Symbols
Operators
Operators
Operator is a symbol that tells the computer to perform certain
mathematical or logical manipulations.
Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
x + y = 32
Eg: Let x=27 and y=5 then x – y = 22
x * y = 115
x % y = 2
x / y = 5
Relational
Operator
C supports the following relational operators:
Operator Meaning
Example: a+=1
is same as a=a+1
Increment &
Decrement
Operator
The Increment Operator (++): The increment
operator (++) is a unary operator that increments the
contents of a variable by 1.
For example, the statement
++ age;
a = ++age;
Assume age = 5. After execution of this statement, a
= 6 and age = 6. In other words, the value of age is
incremented first and then its value is assigned to variable a.
a = age++;
Assume age = 5. After execution of this statement, a
= 5 and age = 6. In other words, the value of age is assigned
first to variable a and then its value is incremented.
Example
#include <stdio.h>
main()
{
int a, b, c, d;
c = 1;
d = 1;
a = ++c;
b = d++;
printf (“The value of a is %d and the value of c is %d.\n”, a, c);
printf (“The value of b is %d and the value of d is %d.\n”, b, d);
}
Conditional
Operator
There is one conditional operator( ?: ) in ‘C’ language. An
expression that makes use of the conditional operator is
called a conditional expression.
Syntax:
expression 1 ? expression 2 : expression 3
Example:
x=(a>b) ? a : b;
Bitwise Operator
There are six bit operators:
Operator Meaning
| Bitwise OR
~ Bitwise NOT
^ Bitwise XOR
m = sizeof (int);
Hierarchy of
Operators
The hierarchy of commonly used operators is shown below: