Professional Documents
Culture Documents
CP
09CE1104
Basic {
Hello World..
#include<stdio.h> Output
void main()
{
Hello World..How are you?
Example printf(“Hello World..”);
printf(“How are you?”);
}
#include<stdio.h> Output
void main()
{ Hello World..
How are you?
Example printf(“Hello World..”);
printf(“\nHow are you?”);
}
As every language contains a set of characters used to construct
words, statements, etc., C language also has a set of characters
which include alphabets, digits, and special symbols. C language
supports a total of 256 characters.
Character set
C language character set contains the following set of characters...
in C Alphabets
Digits
Special Symbols
Alphabets
C language supports all the alphabets from the English language. Lower
and upper case letters together support 52 alphabets.
lower case letters - a to z
UPPER CASE LETTERS - A to Z
Digits
Character set C language supports 10 digits which are used to construct numerical
values in C language.
in C Digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Special Symbols
C language supports a rich set of special symbols that include symbols
to perform mathematical operations, to check conditions, white spaces,
backspaces, and other special symbols.
Special Symbols - ~ @ # $ % ^ & * ( ) _ - + = { } [ ] ; : ' " / ? . > , < \ |
tab newline space NULL bell backspace verticaltab etc.,
Individual words and punctuation marks in C program are called as
C tokens.
OR
A token is the smallest unit in a program.
#include<stdio.h>
C Tokens void main()
{
printf (“Hello World..”) ;
}
C Tokens
Keywords are C tokens that have a strict meaning.
They are explicitly reserved and cannot be redefined.
ANSII C has 32 key words.
C Keywords
auto double int struct
do if static while
Constants
Integer Constants
Floating-point Constants
Constants Character Constants
String Constants
Consists a sequence of digits.
Types of Integers:
Integer Decimal -> 123
Octal -> 0463
Constants Hexadecimal -> 0x8F
These represent numbers containing fractional parts.
Floating
Example: 2.36
point -97.2354
Constants
These represent a single character value.
Example: ‘A’
Character ‘b’
Constants ‘@’
A sequence of characters which are enclosed in double quotes.
String Example: “Computer”
“12345”
Constants
Symbolic representation of a value
Used to store values in program.
It’s value changes as the program statements are
executed.
Variables Example:
x
balance
User_name
A variable definition specifies a data type and contains a list of one or
more variables of that type as follows −
Syntax: type variable_list;
Here, type must be a valid C data type including char, w_char, int, float,
double, bool, or any user-defined object; and variable_list may consist of
one or more identifier names separated by commas. Some valid
Variable declarations are shown here −
int i, j, k;
Declaration char c, ch;
float f, salary;
double d;
Data-Types in
C
Some other data types :
Data-Types in
C
Symbol that indicates the operation or activity to be performed.
Example
+ means addition like A+B
Operators Here, A,B called operands
+ called operator
Operators Unary operator : single operand only, like ++A, -A
Arithmetic
Operators
Used to compare two operands
Relational
Operators
&& (AND operation)
In C form : condition-1 && condition-2
Example :
Logical
Operators
|| (OR operation)
In C form : condition-1 || condition-2
Example :
Logical
Operators
! (NOT operation)
In C form : !condition-1
Example :
Logical
Operators
It copy/store, thus assigning value (It is not exchange the value)
hence the name is assignment operator.
Operators
Example
𝑋 = 𝑌;
𝑋 = 4 + 5;
𝑃𝑖 = 3.1416
Shorthand
Operators
++A (Pre-increment)
Increment/
A=A+1
Decrement
Operators
A++ (Post-increment)
Increment/
Decrement
Operators
Also known as ternary operator.
Conditional
Operator
Bitwise
Operator
Comma operator
value = (x=10, y=5, x+y);
sizeof operator
Give size of particular variable in memory
Special Example:
Operators sizeof(char) is 1 byte
sizeof(int) is 2 bytes
Address operator (&)
Standard input functions:
scanf()
getchar()
gets()
getch()
I/O Function Standard output functions:
printf()
putchar()
puts()
int main()
{
char c;
printf("n Please enter a character:");
I/O Function c=getchar();
printf("n The character entered is: ");
putchar(c);
return 0;
}
void main()
{
/* character array of length 100 */
char str[100];
I/O Function printf("Enter a string");
gets( str );
puts( str );
getch();
}
When a data type is converted into another data type by a
programmer or user while writing a program code of any
programming language, the mechanism is known as type
casting. The programmer manually uses it to convert one
data type into another. It is used if we want to change the
target data type to another data type. Remember that the
Type casting destination data type must be smaller than the source data
type. Hence it is also called a narrowing conversion.
Syntax: Destination_datatype = (target_datatype) variable;
(data_type) it is known as casting operator
int a = 20;
Type Float b;
conversion b = a; // Now the value of variable b is 20.000
/* It defines the conversion of int data type to float data
type without losing the information. */
Conversion
Order
That’s All