C Language-Class Notes
C Language-Class Notes
C Language-Class Notes
PAVAN
PH: 7013088104
=========================================================================
First online session - c programming language
Q) factorial of 120???
silent mode....
Factorial of 5 : 120
ans) so many
All those computer languages are classified into 2 types
2) High Level Languages : language where programmer can feel very easy to write
programs
ex: C,C++, JAVA, PYTHON etc
a) program written in H.L.L are portable
+
2) compiler:
i wrote one c program- 12 lines of instructions
12 lines of program - source code (human
understandable) ===> compiler
3) interpreter
what is compilation?
ans: the process of converting program(source code) into machine understandable
code by the compiler
During compilation ... compiler will find out ---------------- type of erros
ans: syntax
What is syntax?
rules framed by any programming language
what is debugging?
the process of identifying the bug & removing the bug from the program
what is a bug?
error in your program
Interpreter: will convert the total program in to machine understandable code line
by line
compiler
interpreter
1) total - all at a time
1) total - line by line
4) execution is faster
4) execution is slow
5) ex: c, C++
5) python, ruby etc
1969- BELL LAB - TEAM - KEN THOMPSON, DENNIS RITCHIE & TEAM - UNICS(UNIPLEX
INFORMATION & COMPUTING SERVICES)- SINGLE TASKING OS
UNICS - MULTI TASKING OS
ASSEMBLY LANGUAGE: LOT OF PROBLEMS
FAMOUR PROG LANGUAGE: BCPL
KEN THOMPSON: B
DENNIS RITCHIE: NB - 1972 ===> C
OPERATING SYSTEM:
C LANGUAGE
K & R C
ANSI C
C99
C11
IN OLDEN DAYS: PEOPLE CAN USE LOW LEVEL LANGUAGES: SYSTEM S/W: UNIX: C - LOW LEVEL
============================================================
ENGLISH:
ALPHABETS ==> WORDS ==> GRAMMAR ==> SENTENCE ===> PARAGRAPH
C LANGUAGE:
character set==> keywords/identifier/constants
etc=>syntax==>instructions===>Program
Q: what is an identifier?
ans: named elements in the program
Ex: Variable, functions, arrays, structures etc
Q: What is a constant?
Ans: fixed values in the program & these are also known as Literals
Types of constants:
Number constant:
a) integer constant:
1) it must have atleast one digit
2) it must not contains decimal point
3) either + ve or -ve
4) if no sign symbol: default: +ve
5) no special symbols,spaces are allowed
total: 16
ex: 0xFACE
Real constant:
1) is a number must contain one decimal point
2) u should not contain more than one decimal point
3) it may be either +ve or -ve
4) if no sign is specified default: +ve
5) real constant also known as: float point constant
6) represented in 2 ways: decimal form, exponential form
ex for decimal form: 0.21 1.258 99999.99
exponential form: 2.3e+7 9e-12
a : 97 A : 65
b : 98 B : 66
digits:
0 : 48
etc
white space character : 32
8 '8'
"8"
integer constant single character constant
String constant
3) Linking the program: all necessary files are linked in this step to the file
generated in step 2
first.obj + required files ===> first.exe ( machine understandable)
sofware: Linker
4) Loading/executing the program: in this step .exe file will be loaded from hard
disk to
RAM. because when cpu wants to execute your program, instructions must be available
in RAM itself
software: Loader
Q: from developing the application to until execution total how many steps??
ans: 4 steps
Q: in which step object code is generated??
ans: step 2
Q: Loader will transfer the content of .exe file from RAM TO HD??
ans: false
Q: who is responsible to link all necessary files & to add some extra code which is
required to run our program?
ans: Linker
Q) What is a function?
ans: is a collection of instructions
R.T fun_name(inputs)
{
GROUP OF INSTRUCTIONS
}
printf("pavan")
printf("welcome to c programming language")
Note: at the time of calling a function inputs supplied to the function call known
as "arguments"
All the builin function's information (known as function prototype) is available in
header files
for ex: printf -> this function prototype is available in stdio.h ( standard input
output header file)
( function prototype: name of function + how many inputs + what type of inputs +
order + return type)
any statement that starts with # symbols is a preprocessor directive statement
for main function eventhough return type mentioned is "int" type... if u forgot to
write
return statement.... nothing will happen
1) dev c++
2) codeblocks
3) turbo c++
4) onlinegdb.com
5) from command line
1) #include
2) #define ==> create a constant
create a macro
Variable:
is named memory block which holds the data
name elements: identifier
datatype var_name;
ex:
int x;
char ch;
float avg;
4 bytes: 32 bits
double data type: is same as float except accuracy of storing number with decimal
part having precision more than
6 digits
Memory: 8 bytes
Range:
ex: double x,longitude;
syntax:
variable=value;
What is initialization?
at the time of creating a variable, if the value is assigned to a variable then we
can call it as a initialization
datatype formatspecifier
========= ============
char %c
int(decimal) %d or %i
float %f
unsigned int %u
variable1 = variable2
ex:
result = a
variable is hard coded means: when we are assigning some value to a variable with
in a program like the below is nothing but hard coding
ex: int x=34;
float avg=9.8;
char gender='m';
Best approach: take the input for a variable during runtime/ program execution
given by the user
syntax:
scanf("formatted string",listofvariables)
signed int b;
- ve range: -1 to -2,14,74,83,648
+ve range: 0 to 2,14,74,83,647
char: 1 byte: 8 bits: total values: 256 values ( both +ve and -ve)
range for -ve: -1 to -128
range for +ve: 0 to 127
sometimes to meet our requirements (for ex: to store our mobile no : variable must
capable to hold 10 digit number
that should start with either 6/7/8/9) we have to increase the size of the
variables then we have to use size qualifier
on the data type
a) short
b) long
long int phno;
(or)
long phno;
there is no difference between int & long int type under gcc compiler
However to meet our requirement... we can apply qualifier "long" one more time
ex: long long int phno;
(or)
long long phno;
Memory: 8 bytes: 64 bits
to decrease size of int data type we must apply qualifier " short "
ex: short int mks;
(or)
short mks;
==============================================================================
char %c -128 to +127
1
int %d or %i -2147483648 to
2147483647 4
unsigned int %u 0 to
4,29,49,67,295
float %f
4
double %lf
8
const qualifier:
ex: const float pi=3.14; //literally this variable is locked(read only
variable)
int main()
{
int p=-8;
const float pi=3.14;
-------
-------
-------
-------
-------
p=-1;
-------
-------
-------
-------
-------
Operators in "c":
1) Arithemtic operators
2) Relational operators
3) Logical operators
4) Bitwise operators
5) increment & decrement operators
6) Conditional (or) ternary operators
7) other operators: . -> sizeof comma operator etc
Based on no.of operands that operator can take.... operators are classified into
a) Unary operator: if an operator take only one operand to perform operation...
then it is unary operator
ex: unary minus,unary plus, increment,decrement operator etc
b) Binary operator: if an operator takes two operands to perform the operation...
then it is binary operator
Note: All arithmetic operators are binary operators
c) Ternary operator: if an operator takes three operands to perform the
operation... then it is binary operator
Ex: conditional operator (Symbol: ? : )
Arimetic Operators:
================
+ - * / %