C Language Intro

C’ LANGUAGE

Course Designed by RAJ.

C is a structured, middle level, machine independent language.
         In 1960’s, Martin Richards developed a language called ‘BCPL’ (Basic Combined programming Languages) for writing (primarily) system software.
In 1970, Ken Thomson created language using many feature of BCPL and called simply ‘B’.
Both BCPL and B were type less system programming languages. B was used to create early versions UNIX system at Bell Laboratories.

‘C’ was evolved from ‘ALGOL’, ‘BCPL’, and ‘B’ by Dennis Ritchie at Bell Laboratories in 1972, causes many concept from these languages and added the concept of datatypes and other powerful features. Since, it was developed along with UNIX, it is strongly associated with UNIX, which is coded almost entirely in C.

The language became more popular after the publication of the book ‘The C Programming Language by Brian Kernighan and Dennis Ritchie in 1978. The committee approved version in 1989 is known as ‘ANSIC’. It was approved by ISO called as ‘C89’.

C language is an ideal language for developing portable applications and firmware. It is a middle level and general purpose programming language. It was originally developed for writing system software.
C language is ranked amongst most widely used languages and it has a compiler for most of the computer system and has influenced many popular languages like C++.
Features of C language includes:-
·         It has fixed number of keywords and it includes a set of control primitives loops like if, for, while, switch and do while.
·         Includes Bit manipulators and multiple logical and mathematical operators.
·         For a single statement, multiple assignment may be applied.
·         Function return values may be ignored if not needed as it is not always required.
·         All data has type but it can be converted implicitly.
·         Files may be separately compiled and linked.
·         C has only 32 keywords and all the keywords are case sensitive.
·         It follows top to down approach.
·         It provides programming efficiency of high level language like COBOL and execution efficiency of low level language like Assembly or machine language.
·         It is ideal language for system programming.
·         It has very rich set of library function which have been properly categorised and stored into various header files.
                                                                                                  

So now let’s learn something about DATATYPES

What is Datatype?
·         In programming language data type is a set of data with the values having predefined characteristics.
·         Compiler defined data types are known as primitive data types.
·         Structure in C are means to create our own data type which is known as user defined data type.
·         Data type signifies the type of values be intended to store at memory location.

To differentiate the values C uses 5 different data types:-
Data Types
Keyword
Example
Integer
int
1,2,3,4
Character
char
a, b, ch, amt
Real Numbers

float
8.2, 9.5, 12.6
Real numbers with higher degree
double
Big no.s in lakhs
Nothing
void
-

Variables:-
·         Variable is a name given to a memory location, which can store the value temporarily.
·         For ex:- int a;
             float b;
Here, ‘a’ is a variable of datatype integer, whereas ‘b’ is a variable of data type real numbers (float).
·         Variable name is an identifier which identifies or refer to the certain block of memory.
Some Pre-defined functions:-
  1.  printf( );
·         It displays data onto the console (monitor), in formatted form.
·         It returns number of characters displayed on screen or negative value if error occurs.
·         It contains control string and the argument list.
Ex:-
      printf(“ control string with text”, argument list);
·         Control string includes format specifier along with the text.
·         Format specifier controls or specifies how corresponding arguments are to be displayed on screen.
·         Format specifier begins with % sign and is followed by format code.
·         The number of format specifier and number of argument must be exactly equal.

2. scanf( );
·         It reads data from the keyboard and assigns value to the corresponding variables.
Ex:- scanf(“ control string”, argument list);
·         The control string contains format specifier which determines how many values are getting read from keyboard.
·         Control string of scanf neither contain any text nor any escape sequence.
·         Every variable in argument list is preceded by ampercent (&) sign.
·         Scanf requires the address of variable where the value is to be stored.
·         ‘&’ is unary compiled type operator which returns address of variable.
·         The number of format specifier must be exactly equal to the number of variables in argument list.

Some formal codes and their meanings:-
Formal code
Meaning
%c
To print character
%d
To print integer
%f
To print real number
%s
To print string
%i
To print signed integer
%u
To print unsigned integer

Escape Sequence:-
·         It is used for formatting output screen. They are always preceded by ‘\’.

Escape Sequence
Meaning
\n
New Line
\t
Horizontal Tab
\v
Vertical Tab
\b
Backspace
\a
Beep Sound

Operators in c:-
1.   Arithmetic Operators
2.   Relational Operators
3.   Logical Operators
4.   Bit-Wise Operators

Ø  Operators operates on constants or variables which are called as operands.

1.  Arithmetic Operators

Depending on how many operands do they act on, operators are further classified into three types:-
                     I.        Unary Operator
                   II.        Binary Operator
                  III.        Ternary Operator

Unary Operator: - It operates on single data elements.
Ex: - ++,--

       Binary Operator: - It operates on two data elements.
          Ex: - +, -, *, /, %

         Ternary Operator: - It operates on three data elements. It is          used for decision making in C.
         Ex: - C= (a<b) ? a : b;


2.  Relational Operator

They are used to test relationship between two operators.
Ex:- >,<,>=,<=,==,!=

3.  Logical Operators

They are used to combine expressions containing relational operators.
Ex:- &&- AND
        ||- OR


4.  Bit-wise Operator

In ALU which is within the CPU, operations like addition, subtraction, division and multiplication are done in bit-level and to perform bit-level operations in C programming, we use bitwise operators.
Operators
Meaning of operators
&
|
^
~
<< 
>> 


No comments:

Post a Comment