Sie sind auf Seite 1von 13

Intro to c language

 C language is a computer’s programing language.


 C language Is also known as general purpose programing
langugae.
 It is also called “”portable” or “flexible” language.
 Some people say it is a higher level language & some says it is a
middle level language.
 The C language was invented in 1972 by@bell laboratory by
denish M. ritche.
 It was modified by ANSI (american national standard institute) in
1989 and some other companies has also modified it is like “turbo
c”, “dev c”, “visual c”.
 We will learn “turbo C 3.0” version of c language.

C character set
 Remember to learn any language we need to learn basic’s.
 C basic contains 4 categories…
 Alphabets [a,b,…z]
 Numbers[1,2,3…9]
 Special symbols [ &,*,^,%,etc]
 White spaces [space,new lines etc]

C tokens

A word used in C is called token of C.

There are 6 tokens in C language.


1. Keyword
 A word that has it’s own pre-defined meaning in C language
is called keyword.
 There are only 32 keywords in C.
 EG:- int , char , float , if , while , static , extern ,
Far , else , switch-case,etc.
 A keyword appears in white letters always.
 A keyword of C must be written in small letter.

1. Identifiers

 An identifier is made up of C characters set.


 An identifier is used to identify something.
 A word that is used to form a C statement is called an
“identifier”.
 EG:- int , qty , FINE , PI , No , etc.

2. Variables

 C language deals with data and to store data we use a


name. this name is called variable name.
 An entity which is capable of capable of changing it’s
own value itself is called variable.
 A variable name can be made up of letters , numbers,
and some special characters.
3. Rules to define a variable

 A variable name must be started with an alphabetor


underscore.
 A variable name can be made up of letters , numbers &
symbols.
 A variable name can’t be any keyword.
 EG:- int char (here char is a keyword)
 Max length of variable is 31 characters.
 We can’t have two variables with same name in one
program.
 We can’t leave space or give any other sign except
_(underscore) symbol.

4. Strings

 More than one letter is known as strings in C


language.
 Strings in C language is always surrounded within
“ ” (double quotes).
 A string in C language always ends with “\0”
called null characters.
 Each characters stores 1 bytes in string.
 EG:- “A” stores 2 bytes (1 + null).
 “Sanjay sir” occupies 11 bytes.
5).Operators

 An operator is a kind of symbol which is used to


perform any calculation.
 There are different types of operators available in
C.
 We have arithmetic (+,-, etc), relational (> , < etc)
and some other operators in C language.

5. Constants
Mainly constants in C language are of 4 types.
1. Number constants.
2. Character constants.
3. Backslash character constant.
4. Symbolic constant.

(A). Number constants

There are 2 types of number constants available in C


language.

 Integer constants.
 Real constants.
Integer constants

 Integer constant refer to whole numbers.


 The number which are positive or negative whole
numbers are considered as “integer constants”.
 EG:- 20, 633 , -239 etc.

Integer constants are of three types.

1). Decimal integer

2). Octal integers

3). Hexadecimal integers

1). Decimal constants

 The number which are from 0 to 9 (ten


digits) are called Decimal integers.
 They are represented by symbol ( + or -)
sign.
 Its base is called 10. So, when we write
them , we write like (65) base 10, (251) base
10.

2). Octal integers

 The numbers which are from 0 to 7 (total 8


digits) are called octal integers.
 They are represented by o or O sign.
 It’s base is called 8. So when we write them
, we write like (32) base 8.

3). Hexadecimal integers

 The number which are from 0 to 9 and A


to F
 (total 6 digits) are called hexadecimal
integers.
 Where A represents 10, B is 11 , c is 12 & so
on.
 There are prefixed by ox or OX.
 It’s base is called 16.so, when we write
them, we write like (1099) base 16, (A5F3)
base 16.

Real constants

 The numbers which contains fraction


numbers are called real constants.
 The real numbers can be of 2 types.
 Float values :
Values like 20.60, 13.50 , etc are called the
floating point values.
 Scientific values :
Values like 0.775e2 , etc is called scientific
values. where 0.775 is called mantissa and 2
after E/e is called exponent (power).

Character constants : There are two types of character constants.

Single character : a single letter in C language is


called single character constant.

 it is denoted in (‘ ’) IE single quotes.


 Each character is associated with it’s ASCII
value (amercian standard code for
information & interchange).
 EG:- A-65 , a-97 , Z-90 , z-122 , etc.

String character : more than one letter is called


“string”.

 String in C is not associated with any ASCII


value rather it always ends with null (“\0”).
 String in C is denoted by (“ ”) IE double
quotes.

Symbolic constants : certain numeric and character constants can be


defined using symbolic constants.

 Such constants are known as “symbolic constants”.


 To define such symbolic constants we use following syntax :
 EG :- # define PI 3.14
# define rows 10
 Symbolic constants are normally written in
CAPITAL letters.

Backslash character constants :backlash character constants are made


up of two letters and it’s first letter is always a ‘ \ ’. that’s why they are
called backslash character constants.

 They are also called as “escape sequence” as their output is


nothing but a white space.
 They are used for formatting purpose.
 EG :- \n is used to print new line
\t is used to print a horizontal tab.
\a is used to ring a sound\bell.

Progarm structure
1). Documentation : the documentation part is optional.

It is also known as comments.it can be of two types.

 Single line written by \\ (not need to close).


 Multi lines written by \*….*\ (need to be closed.)

 It is not processed by the compilers.


 It’s main purpose to write is to explain the program itself.
 It is very useful in future to know for what purpose the program
was actually written.
 It contains information like…
o The name of the auother.
o The date on which it was created.
o The purpose of the program.
o For whom the program was created.

2). Symbolic constant defination :

o Some times we want some values to remain constants.in


such, cases ,we can define symbolic constants.
o Syntax :-
 #define symbolic_constants value
 EG:- #define PI 3.14
o #define P printf
 In above syntax, #define is called pre-processor directive.
 Whenever symbolic constants occurs in sentence pre-processor
directive tells the compiler to replace it’s value with symbolic
constants.

3). File include section :-

 The file include section is one of the most important part of


C program.
 This section is used to take permission to excecute C library
functions.

 Syntax :-
#include<filename.h>
 In above syntax , #include is pre-processor directive.There
are many library files provided in C program which are
actually used to execute some pre-defined functions also
called as library/built-in functions like printf() , Scanf() ,
clrscr() , getch() , etc.

Library/header file functions which can be executed

1. <stdio.h> printf(), scanf(), getchar()


2. <conio.h> clrscr(), getch(), etc
3. <math.h> pow(), sqrt(), abs() etc
4. <ctype.h> isalpha(), isdigit(), isupper() etc

Global variable declaration

C language provides 2 types of variables.

Local variables local variables are those which are defined inside
any functions like main() or block or passed as an argument to a
function.
Their availability is within the area where they have been defined,
means you can’t use them outside their scope(availability).

Global variables global variables are those which are defined


outside of main() function.

Their availability is within the whole program, means you can use
them anywhere in the program.

Main()

 In C language any program can’t be created without use of


main() function. Actual program execution starts fromt the
first {} bracket after the main () function.
 All C program must contain () function.the control is first
transferred to main() and from here rest of the operators
are carried out.
 All the executable statements will be placed inside the
main() function.
 It is called user defined function(UDF) as everytime user
changes the statements according to his\her requirements.

User defined functions

 If requried user can write more function as per his\her


requirements.such functions are called user defined functions.

EG:- void sum()


Void print()

Int sum(int,int)

Float div(float,float)

Void mul(int,int) etc

Points to be remembered in c language


 Header files must be included before main().
 A executable statement must be inside main().
 Execution of C program starts after first opening {bracket after
main().
 Two functions with same name are not allowed. Normally C
program consist of lower letter, identifier are case sensitive.
 Usually, C statement ends with ; (semicolon).
 Comments can be inserted anywhere where a blank space can be
inserted.
 Every opening{bracket must have} closing bracket.

Das könnte Ihnen auch gefallen