C Unit 2 Note 1st Sem

  

UNIT-2      ELEMENTS OF C LANGUAGE 

 

Notes According to Syllabus: C Standards( ANSI C and C99), C Character Set, C Tokens, Escape sequence, Delimiters, Variables, Data types (Basic, Derived, and User Defined), Structure of a C program, Executing a C program, Constants/ Literals, Expressions, Statements and Comments. 

 

C STANDARDS (ANSI C AND C99) 

There are different standards of the C language. Here we discuss ANSI C and C99. 

  • ANSI C: The American National Standards Institute (ANSI) released ANSI C in 1989. Thats why it’s also called C89. ANSI C is dependent on the POSIX (Portable Operating System Interface) standard. The same standard proposed by ANSI was adopted by ISO officially so ISO/IEC 9899:1990 in 1990. So, it’s also called ISO C and C90. Keywords like const, enum, signed, void and volatile were added, and the keyword entry was dropped in ANSI C. 
  • C99: C99 is the informal name given to the ISO/IEC 9899:1999 standards specification for C that was adopted in 1999. The C99 standard added five more keywords to ANSI C, and the total number of keywords are 37. The added keywords are _Bool, _Complex, _Imaginary, inline and restrict. New header files like <stdbool.h>, <complex.h>, <tgmath.h>, etc. were added in C99.  

 

C Character set

 

The set of characters that are used to words, numbers and expressions in C is called the c character set. The combination of these characters form words, numbers and expressions in C. The characters in C are grouped into the following four categories. 

  1. letters or alphabets 
  2. Digits 
  3. Special Characters 
  4. White space 

1. Letter or Alphabets 

  1. Uppercase alphabets – A…Z 

  1. Lowercase alphabets – a…z 

2. Digits 

All decimal digits – 0 1 2 3 4 5 6 7 8 9 

3. Special Characters 

Symbol 

Meaning 

Symbol 

Meaning 

, 

comma 

& 

ampersand 

. 

period 

^ 

caret 

; 

semicolon 

* 

asterisk 

 

Quotation mark 

# 

Number sign 

- 

Minus sign 

+ 

Plus sign 

[ 

Left bracket 

] 

Right bracket 

% 

Percent sign 

/ 

slash 

etc. 

4. White Spaces 

  • Blank space 
  • Horizontal tab 
  • Vertical tab 
  • carriage return 
  • New line or line feed 
  • Form feed 

 

 

C TOKENS 

 

In a C program the smallest individual units are known as tokens. The basic elements recognized by the C compiler are known as “C tokens”. E.g.: keywords (e.g. Float, while), identifiers (e.g. num, sum), etc. 

 

ESCAPE SEQUENCE 

An escape sequence is a non-printing character used in C. It’s a combination of a backslash (\) followed by a letter or a digit. They represent a single character and have a single ASCII value.  

 

Escape Sequence 

Use 

\a 

Beep sound 

\b 

Backspace delete on character to the left 

\n 

New line of the screen 

\v 

Vertical tab 

\t 

Horizontal tab 

\’ 

Single quote 

\” 

Double quote 

\\ 

Backslash 

\0 

Null Character 

 

 

DELIMITERS 

Delimiters are special characters or symbols which separates words, data or characters in a code. 

e.g. comma (,), terminator (;), full stop (.), etc. 

 

VARIABLES 

A variable is a named location in memory used to hold a value that can be modified by a program. 

  • Variable Declaration: Variables must be declared before you use them. Syntax: data_type var_1, var_2, var_n; 
  • Initialization of a Variable: When a variable, it’s initial value is undefined, before using a variable, you should always initialize it to a known value. E.g. float commission = 0.25; short int height = 110; It’s also written before executing the main program. 

 

DATA TYPES 

A data type defines a set of values that a variable can store value along with a set of operations that can be performed on that variable. C language data types can be classified as: 

  1. Primary or Basic data types: Primary data types are categorized into five types:  

a. Integer Types 

Integers are whole numbers, i.e. non fractional numbers. Generally, integers require 16 bits of storage. C has three further classes of integer – integer (int), short integer (short int) and long integer (long int), in both signed and unsigned forms. The appropriate data type is used according to our requirement i.e. what type of number is to be used. 

b. Floating Point Types 

Floating point types are fractional numbers (i.e. real numbers). They are defined in C by the keyword float. Floating numbers reserve 32 bits (i.e. 4 bytes) of storage, with 6 digits of precision. 

c. Double Precision Floating Point Type 

When the accuracy provided by a float number is not sufficient, the type of double can be used to define the number. A number of data type numbers used 64 bits giving a precision of 14 digits. These are known as double precision numbers. To extend the precision further, long double can be used which uses 80 bits giving 18 digits of precision. 

d. Character Type 

A single character can be defined as a character type data. characters are stored in 8 bits. The qualifier is char. The qualifier signed or unsigned may be used with char. The unsigned char has values between 0 and 255. The signed chart has values from -128 to 127. The conversion character for this type is c. 

e. void Type 

The void type has no values. This is usually to specify a type of function when it does not return any value to the calling function, this is discussed in more detail in the Functions chapter. 

 

  • Derived data type: Derived data types are also known as secondary data types. These are the collection of the same or different primary data types. E.g. Array, Structure, Union, Pointer, etc. 
  • User Defined Data type: C supports a feature called type definition which allows users to define an identifier that would represent an existing data type. The typedef statement is used to give a new name to an existing data type. It allows users to define new data types are equivalent to existing data types. It takes the general form:

typedef  existing_ data_ type new_ name_ for_ existing_ data_ type; 

CONSTANTS / LITERALS 

A constant is a quantity that does not change during the execution of a program. C constants can be divided into different categories. constant is divided into numeric and character constants. Integer and real constants lie in numeric constants while character and string constants lie in character constant types. Types of constant: 

  1. Numeric Constant 
  2. Octal and Hexadecimal constants 
  3. Character Constants 
  4. String Constants 
  5. Symbolic Constants 

Literals are the constant values assigned to the constant variables. E.g. const int = 15; where 15 is an integer literal. 

EXPRESSIONS 

An expression is any valid combination of different entities, for example a constant, a variable, an array element or a reference to a function. 

Expression 

Value 

-4+6 

2 

C = 3+8 

11 

5>3 

1(True) 

6 + (c = 3+8) 

17 

 

 ******

May Devine Goddess protect you all ! Keep faith and hardwork..

! "GOOD LUCK" !


No need to thank, but you can definitely help UJJU_Rizz-ALL by listening this vid full:


Name: Ujjwal Rijal  

Address: Earth

Instagram: www.instagram.com/rijalujjwal87

Twitter: www.x.com/ujjwalreezal

Facebook: www.facebook.com/UjjuGod

Youtube : www.youtube.com/@fyaste


 

 

Comments

Popular posts from this blog

LAB WORK OF PHYSICS (CSIT 1st Sem)

LAB WORK OF DIGITAL LOGICS: (CSIT 1st SEM)

CONQUER IIT(1st SEM) EXAM targeted !!