0% found this document useful (0 votes)
15 views

What is C Language

Uploaded by

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

What is C Language

Uploaded by

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

What is C Language?

• C is a general-purpose computer programming


language.

• C is also said to be structures programming


language or function oriented programming
language.

• C is a High level programming language.


Why do we use C?
• Generally C Language is used to create the
following…
Operating Systems
Language Compilers
Assemblers
Interpreters
Text Editors
Network Drivers
Databases
History of C Language?
• CPL – Common Programming Language invented by
Martin Richards in 1960’s
• BCPL – Basic Combined Programming Language by
Martin Richards in 1966
• B Language – by Ken Thompson & Dennis Ritchie in
1969
• Traditional C – by Dennis Ritchie in 1972
• K&R C – by Kernighan & Dennis Ritchie in 1978
• ANSI C – by ANSI Committee in 1989
• ANSI/ISO C – by ISO Committee in 1990
• C99 – by Standardization Committee in 1999 Dennis
Ritchie
Getting Started with C
Tokens of ‘C’

C language consist of some characters set, numbers and


some special symbols. The character set of C consist of all
the alphabets of English language. C consist of

• Alphabets a to z, A to Z

• Numeric 0,1 to 9
• Special Symbols {,},[,],?,+,-,*,/,%,!,;,and more
Tokens of ‘C’

The words formed from the character set are building


blocks of C and are sometimes known as tokens. These
tokens represent the individual entity of language.

The following different types of token are used in C-

• 1) Identifiers 2)Keywords 3)Constants


• 4) Operators 5)Punctuation Symbols
Identifiers
• A 'C' program consist of two types of elements , user
defined and system defined. Idetifiers is nothing but a
name given to these elements.
• An identifier is a word used by a programmer to name a
variable , function, or label.
• Identifiers consist of letters and digits if any order,except
that the first character must be letter or _.
• Both Upper and lowercase letters can be used
Constant
• A constant is an entity that doesn’t change whereas a
variable is an entity that may change.

Types of C Constants

C constants can be divided into two major categories:

(a) Primary Constants


(b)Secondary Constants
Constant
Rules for Constructing Integer Constants

(a) An integer constant must have at least one digit.


(b)It must not have a decimal point.
(c)It can be either positive or negative. If no sign precedes an
integer constant it is assumed to be positive.
(d)No commas or blanks are allowed within an integer constant.
(e)The allowable range for integer constants is -32768 to 32767.
Rules for Constructing Integer Constants

Truly speaking the range of an Integer constant depends upon the


compiler. For a 16-bit compiler like Turbo C or Turbo C++ the
range is –32768 to 32767. For a 32-bit compiler the range would
be even greater.

Ex.: 426
+782
-8000
-7605
Rules for Constructing Real Constants

Real constants are often called Floating Point constants. The real
constants could be written in two forms—Fractional form and
Exponential form.
Following rules must be observed while constructing real
constants expressed in fractional form:
(a) A real constant must have at least one digit.
(b) It must have a decimal point.
(c) It could be either positive or negative.
(d) Default sign is positive.
(e) No commas or blanks are allowed within a real constant.
Rules for Constructing Real Constants

The exponential form of representation of real constants is usually


used if the value of the constant is either too small or too large.In
exponential form of representation, the real constant is
represented in two parts. The part appearing before ‘e’ is called
mantissa, whereas the part following ‘e’ is called exponent.
Ex.: +3.2e-5
4.1e8
-0.2e+3
-3.2e-5
Rules for Constructing Real Constants

Following rules must be observed while constructing real


constants expressed in exponential form:
(a) The mantissa part and the exponential part should be
separated by a letter e.
(b) The mantissa part may have a positive or negative sign.
(c) Default sign of mantissa part is positive.
(d) The exponent must have at least one digit, which must be a
positive or negative integer. Default sign is positive.
(e) Range of real constants expressed in exponential form is
-3.4e38 to 3.4e38.
Rules for Constructing Character Constants

(a)A character constant is a single alphabet, a single digit or a


single special symbol enclosed within single inverted commas.
Both the inverted commas should point to the left.
For example
’A’ is a valid character constant whereas ‘A’ is not.
(b)The maximum length of a character constant can be1
character.
Ex.: 'A'
'I'
'5'
'='
Keywords
• Keywords are nothing but auto double int struct

system defined identifiers. break else long switch


• Keywords are reserved words of
case enum register typedef
the language.
• They have specific meaning in char extern return union
the language and cannot be
const float short unsigned
used by the programmer as
variable or constant names continue for signed void
• C is case senitive, it means
default goto sizeof volatile
these must be used as it is
• 32 Keywords in C Programming do if static while
Variables
• A variable is nothing but a name given to a storage area
that our programs can manipulate. Each variable in C has
a specific type, which determines the size and layout of
the variable's memory; the range of values that can be
stored within that memory; and the set of operations that
can be applied to the variable.
• The name of a variable can be composed of letters, digits,
and the underscore character. It must begin with either a
letter or an underscore. Upper and lowercase letters are
distinct because C is case-sensitive
Rules for Constructing Variable Names
(a) A variable name is any combination of 1 to 31 alphabets,
digits or underscores. Some compilers allow variable names whose
length could be up to 247 characters. Still, it would be safer to stick
to the rule of 31 characters. Do not create unnecessarily long
variable names as it adds to your typing effort.
(b) The first character in the variable name must be an alphabet or
underscore.
(c) No commas or blanks are allowed within a variable name.
(d) No special symbol other than an underscore (as in gross_sal)
can be used in a variable name.
Rules for Constructing Variable Names
(a) A variable name is any combination of 1 to 31 alphabets,
digits or underscores. Some compilers allow variable names whose
length could be up to 247 characters. Still, it would be safer to stick
to the rule of 31 characters. Do not create unnecessarily long
variable names as it adds to your typing effort.
(b) The first character in the variable name must be an alphabet or
underscore.
(c) No commas or blanks are allowed within a variable name.
(d) No special symbol other than an underscore (as in gross_sal)
can be used in a variable name.
Syntax For Declaring Variable Names
C compiler is able to distinguish between the variable names by making
it compulsory for you to declare the type of any variable name that you
wish to use in a program. This type declaration is done at the beginning
of the program.
Syntax :
• <type> <variable_name>; or type variableName ;
• Multiple Variables:
• <type> <variable1>, <variable2>, ..., <variableN>;
Initializing Variables:
• <type> <variable_name> = <initial_value>; or type variableName =
value;
Syntax For Declaring Variable Names
Following are the examples of type declaration statements:

Ex.: int si, m_hra ;


float bassal ;
char code ;
Hungarian Notation For Declaring Variable Names
Hungarian notation is a naming convention used in programming,
originally popularized by Charles Simonyi at Microsoft. It involves
prefixing variable names with identifiers that denote the variable's
data type or purpose.
Components of Hungarian Notation:
1) Prefixes: Hungarian notation uses prefixes to indicate the type or
purpose of a variable. The prefix typically consists of one or more
lowercase letters followed by an underscore.

Cont--
Hungarian Notation For Declaring Variable Names
2) Type Indicator: The prefix often denotes the data type of the
variable. For example:
i for integer (int)
f for float (float)
c for character (char)
b for boolean (bool)
ptr for pointer (*)

Cont--
Hungarian Notation For Declaring Variable Names
3) Purpose Indicator: Sometimes, the prefix indicates the purpose
or usage of the variable:
– n for a count or number
– sz for a zero-terminated string (char*)
– p for a pointer
Examples of Hungarian Notation:
• int iCount; (where i indicates integer)
• float fTemperature; (where f indicates float)
• char *pszName; (where psz indicates a pointer to a zero-terminated string)
• BOOL bIsReady; (where b indicates a boolean)

You might also like