KEMBAR78
C Notes | PDF | Computer Program | Programming
0% found this document useful (0 votes)
7 views13 pages

C Notes

The document provides an overview of computer programming, focusing on the C programming language, its history, syntax, and key concepts such as variables, data types, and control structures. It explains the roles of compilers, loaders, and linkers in the programming process, as well as the importance of syntax and semantic errors. Additionally, it covers various programming constructs including loops, conditional statements, and the use of header files.

Uploaded by

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

C Notes

The document provides an overview of computer programming, focusing on the C programming language, its history, syntax, and key concepts such as variables, data types, and control structures. It explains the roles of compilers, loaders, and linkers in the programming process, as well as the importance of syntax and semantic errors. Additionally, it covers various programming constructs including loops, conditional statements, and the use of header files.

Uploaded by

adititomar219
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

What is a computer it is a device capable of performing computations and

making logical decisions at higher speeds of millions and billions times faster
than what humans can
program set of instructions that are arranged in a sequence to guide a
computer to find a solution to given problem
programming the process of writing a program is called programming
source code the programmer writes a set of instructions using a specific
programming language such instructions are called source code
compiler first converter second convert source code to machine readable
language or zero one in one go
converts high level programming language to low level programming language
object code resultant code is converted from source code to binary called
object code
interpreter converter
convert source code to machine readable language or zero one line by line
converts high level programming language to low level programming language
intermediate code resultant court is converted from source code to binary is
called intermediate code
lingkar
link editor binder
• It's a program that combines object modules to form an executable
program
• divides entire program in short modules
• Convert all short modules in object code
• finally linker links back all object codes in one single program compile
automatically involves linker as last step in compiling a program
loader
1. It is a special type of program that copies prog. From storage device to
main memory, where they can be executed.
2. Task of loader is to bring the program & all its related files into the main
memory from where it can be executed by the CPU.
The functionality of the loader is generally hidden from the programmer
Programming language
1. Have syntax and semantics
2. Have unique set of keywords & special syntax for organizing program
instructions

 The programming lang. C was developed in 1972 at AT & T’s Bells


laboratories of USA. It was developed by DENNIS RITCHIE to be used by
the UNIX Operating System.
 C is derived from other 3 languages-
a. ALGOL(1st language to use a block structure)- ALGOL was introduced in
1960’s & was a way of developing ‘STRUCTRURED POGRAMMING
CONCEPT’
b. . BCPL(Basic Combined Programming Language)- developed in 1967 by
Martin Richards developed this language. BCPL was basically a type-
less(had no concept of datatypes) language which facilitated the user
with direct access to memory, which was useful for system
programming.
c. c. B (Basic)- developed in 1970 by Ken Thompson. He developed this & it
was for 1st version of UNIX.
d. C language was developed in 1972 which took concepts from ALGOL,
BCPL, B
C is called Middle Level Language
 It combines best features of HLL and control and flexibility features of
ALL/LLL.
 Combines features of ALL which help in writing business software
packages.
 Allows manipulation of bits, bytes & address-the basic elements with
which computer functions.
C is portable. Platform independent

Cs character set
 Single quotes- ‘ ’
 A-Z, a-z, 0-9, special symbols.
 Eg- ‘2’ , ‘B’, ‘j’, ‘@’, ‘&’
Identifiers
 Identifies data & other objects.
 Identifiers are names given to elements such as variables, arrays &
functions.
Rules for identifires name
 Consists of alphabet, digit, or an underscore.
 Cannot include any special character or punctuation marks (like- #, $, ^,
?, .) except underscore ( _ )
 __
 Keywords-
 Case sensitive
 Must begin with an alphabet or _
 Any length less than 32 characters
VARIABBLE
 A variable is defined as a meaningful name given to the data storage
location in computer memory.
 When using a variable we actually refer to address of memory where
the data is stored.
 Numeric and character variables.

 How to declare a variable


Each var. to be used must be declared with datatype.
 Always declare a variable before using it.
 Should be declared closed to the point of use in SC
 Ends with semicolon ( ; )
 Var. cannot be of type void
Declaring a variable
 Giving values to variables declared is called initializing with initial value.
 If you do not initialize any value it takes default values.
 Default values are garbage values.
Constants
 There value do not change
 Fixed values, explicit data values specified by programmers.
 Eg- pi
Syntax error
1. If syntax error found in code then compiler will not perform its task of
converting to object code.
2. Syntax errors may be spelling, typing mistakes
3. How we write something.
4. Remove these errors first to get output
5. Shows no output
Eg- int a=5 (semicolon missing)
Eg- x_y+z (underscore is not ‘=‘ operator)
Semantic Error/Logical Error- run time error
1. If it occurs program does not works accurately.
2. Run-time error.
3. Meaning is wrong
4. We get output
5. But we get wrong output
Block structured language
 C is not a block structured language. Because it does not allow defining
function within a function or block within a block.
compilation before execution

streams
 Vario0us streams for input and output are there.
 Acts in 2 ways- source & destination
 C program I/P & O/P data from stream
 Streams are associated with physical device such as the monitor or a file
stored on the secondary memory
Header files

program requirements

 Stdio.h
 Conio.h
 .c file
 .h file
 .o file
 .exe file
 Printf()
 Scanf()
 Printf-Is used to convert data stored in the program into a text stream
for give output on the monitor.
 printf()- stands for PRINT FORMATING.
 Used to display information required by the user and also to print values
of the variables.
 Scanf Is used to convert text stream coming from the keyboard to fata
values & stores them in program variables.
 scanf()- stands for SCAN FORMATING.
 Used to store formatted data from the keyboard.
 ‘&’- address of operator
 is must before variable name- it stores address of variable.
Access specifiers
 Integer- %d
 String- %s
 Float- %f
 Character-%c
 Long Double- %L
 Short/unsigned integer-%h
 Long/unsigned integer-%l
➢ By default all the instructions are executed from top to bottom step-by-
step in sequence.
➢ But, if we want to execute only selected statements, we use decision
control instructions or statements in C language.
➢ Conditional Branching Statements helps us to jump from one part of
program to another depending on whether a particular condition is
satisfied or not.
➢ It includes following 4 types of statements-
a. if stmt. c. if- else- if stmt
b. if- else stmt. d. switch case stmt
dangeling else problem
• With nesting of if- else statements, we often encounter a problem
called ‘Dangling else problem’
• This problem is created when there is no matching else for every “if
statement.” In such cases ‘C’ always pairs an else statement to the
most recent unpaired “if statement” of current block.
Looping control statements slash iterative
➢ Loop control statements are used to repeat some portion of program
either a specified number of times or until a particular condition is being
satisfied. This repetitive operation is done through a loop control
instruction.
➢ C programming supports 3 kinds of looping statements-
a. while loop- entry control loop (3)
b. do-while loop-exit control loop
c. for loop- alternative of while (single)
ptr
1. The for loop allows to specify three things about a loop in a single line-
a. Setting a loop counter to initial value
b. Testing the loop counter to determine whether the condition is TRUE/
FALSE.
c. Increment/decrement/update the value of variable.
d. When for loop is used loop variable is initialized only once.
e. 3. For loop is tested before the statement contained in the body are
executed.
. In a for loop any or all the expressions can be omitted. In case all the
expressions are omitted then their must be two semicolons in the for
statement.
Eg: int i=0;
for( ; ; )
printf(“%d %d”, i++,i<6);
5. There must be no semicolon after for statement. If you put that an
unexpected result will come.
Eg: for( i=0;i<10 ;i++);
printf(“%d“,i);
. Multiple initialization must be separated by comma operated
Eg: int i=0,sum;
for( i=0,sum=0;i<10 ;i++)
sum+=i;
printf(“%d %d”, i++,i<6);
7. Multiple conditions in the test expression can be tested by the logical
operator (&& or ||)
Multiple statements can be included in the third part of the for statement
by using comma operator
Eg: for( i=0,j=10;i<j; i++,j--)
9.Controlling variables can be incremented/decremented by values other
than 1.
Eg: int i;
for( i=1; i<=10; i+=2)
printf(“%d”, i);
10. Never use a floating point variable as the control variable because it is
just approx. & therefore, may lead to inaccurate results.
Never use a floating point variable as the control variable because it just
gives approx. values & therefore, may lead to inaccurate results.
Eg: float i;
for( i=100; i>=10; i--)
{
printf(“%f”, i);
i=(float)i/10;
}
Switch case versus if else
• A float expression can never be tested using switch case.
• Multiple cases cannot use same expressions. Thus following is illegal-
Eg- Switch(a)
{ case 3:
case 1+2:
}
• Case in switch can never have variable expressions(like- case a+3: )->
WRONG
• Advantages of using switch caseA float expression can never be tested
using switch case.
• Multiple cases cannot use same expressions. Thus following is illegal-
Eg- Switch(a)
{ case 3:
case 1+2:
}
• Case in switch can never have variable expressions(like- case a+3: )->
WRONG

You might also like