0% found this document useful (0 votes)
20 views9 pages

C Programming Basics Guide

The document provides an introduction to the C programming language, highlighting its structured nature, modular programming capabilities, and portability across different systems. It covers the history of C, its character set, tokens, data types, and constants, along with examples of identifiers, keywords, and user-defined data types. Additionally, it explains variable declaration and initialization, emphasizing the rules for constructing valid identifiers and variables.

Uploaded by

Sampurna prusty
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)
20 views9 pages

C Programming Basics Guide

The document provides an introduction to the C programming language, highlighting its structured nature, modular programming capabilities, and portability across different systems. It covers the history of C, its character set, tokens, data types, and constants, along with examples of identifiers, keywords, and user-defined data types. Additionally, it explains variable declaration and initialization, emphasizing the rules for constructing valid identifiers and variables.

Uploaded by

Sampurna prusty
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/ 9

Introduction to C programming:

Introduction to C:
 ‘C’ is a Structured Programming Language
 It is considered as a middle level language as it supports some of the features of low level language also.
 ‘C’ is a case sensitive language i.e., upper case letters and lower case letters are distinct.
 It is well suitable for developing application software as well as system software.
 It supports the concept of “Modular Programming”, which means that a larger task is divided in to a
number of sub tasks each subtask is referred to as a “module” or a “function”.
 Due to this modular programming, it is easy to identify and rectifies the errors. Execution speed also
increases.
 ‘C’ language is highly portable. i.e., a ‘C’ program written for one computer can be easily run in another
computer under certain conditions.
 It supports data structures like arrays, pointers, structures and unions.
 The power of ‘C’ is increased due to the support of a number of library (or) inbuilt functions.
 ‘C’ has a special type of operators called “Bitwise” operators.

History of ‘C’:

Year Language Developer

1960 ALGOL-60 International Committee


1963 CPL Cambridge University
1967 BCPL Martin Richards [C.U]
1970 B Ken Thomsen [AT&T Bell Laboratories]
1972 C Dennis Ritchie [AT&T Bell Laboratories]

 ‘C’ is a general purpose structured programming language.


 ‘C’ was originally developed in ‘1972’ by “Dennis Ritchie” at “AT&T” Bell Laboratories.
 It is an outgrowth of two earlier languages called “BCPL” {Basic Common Programming Language} &
“B” which were also developed at Bell laboratories.

C- Character Set:
 The set of characters supported by ‘C’ language is called “C-character set”.
 The ‘C’ character set contains Alphabets, Digits and Special characters.
Alphabets: A, B . . . . . . . . . . . Z {upper case, ASCII – 65-90}.
a, b . . . . . . . . . . . . z {lower case ASCII 97 – 122}.
Digits: 0 . . . . . . . . 9 {ASCII - 48-57}.
Special Characters:
+, <, >, {}, ., &, *, :, [,], @, ~{tilde}, %, \{Back slash}, /, ,, ?, =, ;, |, #, “, !, ^, -.
 ‘C’ uses certain combinations of above characters to represent special characters like backspace, new line,
horizontal tab, vertical tab and form feed.
 White space is also allowed by the ‘C’. It is also considered as a character.

C-Tokens:
These are smallest individual units. They may represent a single character (or) a group of characters
which has a specific meaning.
 The following are the ‘c’ tokens that can be recognized by “C compiler”.

C-Tokens

Identifiers Strings Keywords Constants Operators


1. Identifiers :
 These are the names that are given to the various program elements such as variables, functions, arrays,
structures, etc.
 These are user defined names.
Limitations:
 It allows alphabets, digits and the special character underscore (_).
 Both upper case & lower case letters are permitted.
 Upper case & lower case aren’t interchangeable
 An identifier name should not start with a digit.
 It can start with either an alphabet (or) underscore. [An identifier starting with underscore is rarely done in
practice].
 Keywords (or) reserved words should not used as identifiers.
Eg: area, Max_Price ,_total -Valid Identifiers
Min area, ‘a’, “college” –not valid Identifiers.
 Identifiers can be arbitrarily long but some c-compilers recognize only the first eight characters.

Key words:
 These are also called “reserved words”.
 They have standard and pre-defined meaning in ‘c’. These keywords can be used only for their intended
purpose. They can’t used as programmer defined identifiers.
 In general the keywords are represented by using lower case letters.
 ‘C’ language supports nearly 32 key words.
 Eg: auto, extern, const, int, long, signed, unsigned.
Data Types
 It specifies the type of the data, the size of data and about the range of data.
 ‘C’ supports a several different types of data types.

Built-In:
Data Type Size (in bytes) Range
int 2 -32768 to 32767
unsigned int 2 0 to 65535
signed 2 -32768 to 32767
short 2 -32768 to 32767
unsigned short 2 0 to 65535
signed short 2 -32768 to 32767
long 4 -2147483648 to 2147483647
unsigned long 4 0 to 4294967295
signed long 4 -2147483648 to 2147483647
char 1 -128 to 127
unsigned char 1 0 to 255
signed char 1 -128 to 127
float 4 3.4E -38 to 3.4E +38
double 8 1.7E -308 to 1.7E +308
long double 10 34E -4932 to 34E +4932
Note:
 Float is a single precision value. {After decimal 7 digits has been considered}
 Double is a double precision value. {After decimal 14 digits has been considered}
 In-Built data Types are supported by ‘C’ compiler by default.
void:
 It is a special data type used for
o To specify that a function doesn’t returns any value.
o To specify a function takes no arguments.
o To create generic pointers.
Eg: 1. void print (void)
2. void *ptr
Derived Data Types:
 Derived Data Types has been derived from built in data types.
Various data types are discussed below.
Arrays:
 An array is a collection of homogenous {similar} type of data
 An array element is stored in continuous fashion.
Eg: 1) int a [10];
2) float avg [20];
Functions:
A Function is a sub program which performs a specific task, function is a topic related to the concept of
modular programming where a larger task is divided in two smaller tasks. Each smaller is referred to as module
(or) a function.
Eg: void swap ( int a , int b)
{
int t;
t = a;
a = b;
b = t;
printf (“%d %d “, a, b);
}
Pointers:
 A pointer is a variable which can store the Address of another variable. Pointers increase the execution
speed of a program.
Eg: int a,b;
int *p;
p = &a;
Here ‘p’ is a pointer.
User Defined Data Type:
 User defined data types are the data types that are created by the user.
Structures:
 It is a collection of Heterogeneous {dissimilar} type of data.
Eg: struct student
{
int roll no;
char name [20];
float avg;
};
Here struct is a keyword and student is the structure name.
Unions:
As per the definition, both structure and the union are same. The difference between structure and union is in
memory allocation.
Eg: union date
{
int day;
int month;
int year;
};
Enumerations:
 These are used to assign constant values to the strings.
Eg: enum color{ red, green, black,}
Here enum is the keyword and red has been assigned value zero, green to 1 and black to 2.

Constants:
 These are fixed values that will not change during the execution of program.
 There are 4 basic types of constants in ‘C’. They are
o Integer Constant
o Floating Point Constant
o Character Constant
o String Constant

Integer Constant:
An integer constant is an integer valued numbers.
Rules for Constructing Integer Constant:
 It shouldn’t have a decimal point.
 An integer constant must have at least one digit.
 Commas, Blank spaces, special characters can’t be included with in the constants.
 The constant can be preceded by a minus sign if desired.
 The range of integer constants is -32,768 to 32,767
Types of Integer Constants:
 Integer Constants can be written in 3 different number systems, namely
o Decimal {Base = 10}
o Octal {Base = 8}
o Hexa Decimal {Base = 16}
Decimal Numbers:
 A Decimal integer constant can consists of any combinations of digits taken from the set 0-9.
 If the constant contains 2 (or) more digits, the first digit must be something other than zero.
Eg: 0,1,723,32156.
Octal Constants:
 An Octal integer constant can consist of any combination of digits taken from the set 0-7.
 The first digit must be zero in order to identify the constant as an octal number.
Eg: 0,01,0723.
Hexa Decimal Numbers:
 A Hexa Decimal integer constant must begin with either 0x, (or) 0x.
 It can be consists of the digits taken from the set 0-9, and a-f {either upper case (or) lower case}.
 The letters a-f, represent the quantities 10-15 respectively.
Eg: 0x, 0x, 0x7.
Unsigned & Long Integer Constants:
 An Unsigned integer constant can be identified by appending the letter ‘u’. {either upper or lower case}
 Long interval constants can be identified by appending the letter ‘L’ {either upper or lower case} to the end
of the constant.
 An unsigned long interval constant can be specified by appending the letters UL {either upper case (or)
lower case} to the end of the constants.
 Note that ‘u’ must precede the ‘L’.
Eg: 234U – Unsigned Decimal Constant
0427UL – Unsigned Long Octal Constant
0X72FL – Long Hexa Decimal Constant
Floating Point Constants:
 A floating point constant is a decimal number that contains a decimal point.
Rules:
 Commas and Blank spaces can’t be included.
 It can contain of either decimal point (or) Exponent.
 The constant can be preceded by minus sign it desired.
Eg: 0, 1., 12.3.
Scientific Notation:
 When we want to represent very large values (or) very small values, instead of representing the value of
sequence of digits we can represent a floating point constant value in a scientific notation as follows.
Mantissa E (or) e exponent.
Eg: 1.2E + 3 => 1.2 * (10^3)
 Note that if no sign is represented after ‘E’ it will be treated as positive.
 Floating point constants are identified by appending the letter F {either upper case (or) lower case} to the
end of the constants.
Eg: 3E5F = 300000F.
Character Constants:
 A character constant is a single character enclosed in single quotation marks. The Max length of character
constant is “one”. The single character can be either alphabet (or) Digit (or) a special symbol.
 Eg: ‘a’, ‘1’, ‘?’.
Note: Most computers make use of the “ASCII” {American Standard Code for Information Interchange”},
character set, in which each individual character is numerically encoded.
 ASCII code is a 7 bit code. ASCII values ranges from 0-127.

Back Slash Characters : ( Escape Sequences)


 The Back Slash characters are used to denote non-graphic characters and other special characters for a
specific operation.
 These are also known as escape sequences.
 Some of the Back slash characters are listed.
Back Slash Character Meaning
\a Alert a bell character
\n New line {line feed}
\t Horizontal Tab
\b Back Space
\r Carriage return
\f Form feed
\v Vertical tab
\l Backslash
\’ Single quote
\0 Null character
\? Question Mark
\000 Octal Value
\xhhh Hexa decimal values
String Constants:
 A String Constant consists of any number of consecutive characters enclosed in double quotation marks.
Eg: “ved”, “college”, “ “.
Variable:
 A variable is an identifier that is used to represent a single data item.
 The data may be numerical quantity (or) a character constant.
 The data item must be assigned a value to the variable at some point in the program. Then data item can be
accessed by referring to the variable name
 In other words, a variable is an identifier which changes its value during the execution of the program.
Rules for Constructing a Variable:
 A variable name is a combination of alphabets, digits and underscore.
 Other than the underscore no special characters is allowed.
 The first character in the variable name must be an alphabet.
 The variable name should not be of keyword.
Declaration of a Variable:
 Any variable which is used in the program should be declared first. A declaration of a variable specifies
two things:
o It tells the compiler about the name of the variable.
o It specifies about the type of data that a variable can hold.
 Syntax: data type variable 1, variable 2 , . . . . . . . . variable ;
Eg: int a, b, c;
 The above declaration results in declaring the variables a, b, c as integer data type.
Initialization of Variable:
Assigning a value to a variable at time of declaration is called initialization of a variable.
Ex:- int a=20;

You might also like