Sunday, December 22, 2019

Constants & Variables in C

⇒ Constant:-

    Constant is a value that can't be change during the execution of program. They are classified into following type

  1. Numeric Constant:-

(a) Integer Constant:-

    -These are the sequence of numbers from 0 to 9 without decimal points or fractional part of any other symbols. It required minimum two bytes and maximum four bytes.
    -Integer constant could be either positive or negative or may be zero e.g. -10,20,+35,-15 etc
    -They can also be represented in octal or hexadecimal number 
e.g. 
  • Octal no.- 027,035,079 etc.
  •  Hexadecimal no.- 0X9,0Xab,0XA etc.

(b) Real Constant:-

    -Real constant are also known as floating point constant. Integer constant are not fit to represent many quantities e.g. Length,Height,Distance etc.

    2. Character Constant:-

(a) Single character constant:-

    -A character constant is a single character constant.
    -It can also be represented with single digits ore single special symbol or white space enclosed within a pair of single quote (' _ ') mark e.g. 'a','8','_','D' etc.

(b) String Constant:-

    -String constant are a sequence of characters enclosed within double quote("_") mark.
    -The string may be a combination of all kind of symbol e.g."Hello","India","999","a".

 Variable:-

    -Variable is a value that can be change during the execution of program. A variable is a data name use for storing a data value. In other words a variable can be assign different value  at different times during the program execution. 
    -A variable name may be declared based on the meaning  of the operations. Variable names made up of letters and digits. Variable are the basic objects manipulated in a program.
    -Variable declaration gives an introduction of variable to compiler and its properties like scope, range of values and memory required for storage.
    -A variable is used to store values. It have memory location and can store single value at a time e.g. Height,Average,Sum etc.

Rules for Declaring Variable:-

  • A variable must be begin with a character or an underscore(_) without space. The underscore is treated as one type of character.
  • It is advised that the variable name should not start with underscore because library routines mostly use such variables name.
  • The length of the variable varies from compiler to compiler. Generally most of the compiler support 8 character excluding extension .
  • The ANSI standard recognizes the maximum length of a variable up to 31 characters.
  • The variable should not be a C-keyword.
  • The variable name may be a combination of UPPERCASE and lowercase character e.g. suM,sum etc.
  • The variable name should not start with a digits.
  • Blanks & Commas are note permitted with in a variable name.

Tuesday, December 17, 2019

Tokens, Keywords & Identifiers in C Programming Language

⇒ The C Declaration:-

  • The programming language are designed to support certain kind of data such as numbers, characters, strings etc to get useful output known as result data consist of digits alphabets and symbols.
  • A program should support these data type for getting the required output known as Information.
  • A program is a set of statement which perform a specific task executed by user in a sequence form.
  • These statement or instruction are formed using certain words and symbols according to the rules known as syntax rule or grammar of the language.
  • Every program must accurately follow the syntax rule support by the language.

⇒ TOKENS:-

          The smallest unit in a program or statement is called a token.Tokens are classified in the following types -
  • Keywords: Keywords are reserve word by the compiler. There are 32 keywords.
  • Variables: These are user defined. Any numbers of variables can be defined.
  • Constant: Constant are assigned to variable.
  • Operators: Operators are different types and are used in different declaration in 'C'.
  • String: A sequence of Characters.


⇒ KEYWORDS:-

    The C-keywords are reserved word by the compiler. All the C-keywords have been assigned fixed meaning and they cannot be used as variable names.It is suggested that the keywords shouldn’t be mixed up with variable name.For utilizing the keywords in a program no header file is required to be include.

         There are 32 keywords available in ANSI C
i.e. auto, break, case, char, const, continue, default, do, double, else, enum, extern, float, for, goto, if, int, long, resister, return, short, signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while.

⇒ IDENTIFIERS:-

  •  A symbolic name is use to refer to a variable, constant, function, structure, union etc.
  • Identifiers are the name of variable, functions, arrays etc.
  • They refer to a variety of entities such as structures, union, constant, functions, and objects.
  • An identifier always starts with an alphabet and it’s a plane sequence of alphabets and/or digits.
  • C-Identifiers doesn’t allow blank spaces punctuation and signs.
  • Identifiers are user defined names. They are generally defined in lower case latter. However, the upper-case latter are also permitted.
  • The underscore (_) symbol can be used as an identifier.
  • Valid identifiers are: length, area, volume, sUM.
  • Invalid identifiers are: length of line, s+um, year’s.


Sunday, December 15, 2019

History of C Programming language


  • The base or father of programming language is ALGOL(Algorithmic Language).
  • It was 1st introduce in 1960. ALGOL introduce the concept of structure programming.It was the 1st computer language to use a block structure.

  • In 1967 a new computer programming language was announced called BCPL(Basic Combine Programming Language). BCPL was developed by Martin Richards especially for writing system software.
  • In 1970 a new programming language called 'B' was introduce by Ken Thompson that contain multiple feature of BCPL. 'B' language was used to create early version of UNIX operating system.
  • In 1972 Dennis Ritchie created a new programming language called 'C' at Bell Laboratories by using 'ALGOL', 'BCPL', & 'B'.programming language.
  • C Programming language contains all the feature of these language and many more additional concept that make it unique from other language. 

  • In 1978 Dennis Ritchie and Brain Kernighan publish the 1st edition of 'The C Programming Language' book.The book was so popular after publication of the book & the language are commonly known as "K&R C".
  • In 1983 the American National Standard Institute (ANSI) established a committee to provide a modern comprehensive definition of 'C'. The resulting  definition ANSI standard or 'ANSI C'  was completed in 1989.
  • In 1990 it was approved by the ISO(International Standard Organisation). It is also know as C90 standard.
  • The next revision C99 standard was published in 1999 that introduce new features like advance data types and other changes. Then the new revision completed at the very end of 2011 is known as "C11".
Programming Language
Development Year
Founder
ALGOL
1960
International Group
BCPL
1967
Martin Richards
B
1970
Ken Thompson
Traditional C
1972
Dennis Ritchie
K&R C
1978
Brain Kernighan and
Dennis Ritchie
ANSI C
1989
ANSI Committee
ANSI/ISO C
1990
ISO Committee
C99
1999
Standardization Committee
C11
2011
Standardization Committee


Saturday, December 14, 2019

Introduction to C Programming

  • C is a general purpose programming languages that is extremely popular, simple and flexible. It is machine independent, structured programming language, which is used in various application. 
  • It was developed by Dennis Ritchie at AT & T Bell Laboratories in 1972.
  • It can be defined by the following way i.e.
  1. Mother Language
  2. System Programming Language 
  3. Procedure oriented Programming language
  4. Structure programming language
  5. Mid-level Programming language



1. C as Mother Language:

    C language is considered as the mother language of all the modern programming languages because most of the compilers JVMs(Java Virtual Machine) Kernels are written in C language & most of the programming language follows the C syntax.
e.g. C#, JAVA, C++ etc.

2. C as a System Programming Language:

    A system programming language is used to create system software. C language is a system programming language because is can be used to do low level programming. It is generally used to create hardware devices, OS, drives etc

3. C as a Procedure Programming Language:

    A procedure language specify a series of steps for the program to solve the problem. A procedure language breaks the program into function, data, structure etc.

4. C as a Structure Programming Language:

    A structure programming language is a subset of a procedure language structure means to break a program into parts or blocks, so that it may be easy to understand.
    In the C language we break the program into parts using function. It makes the program easier to understand and modify.

5. C as a Mid-level Programming Language:

    C is considered as a middle level language because because it supports the features of both low level and high level language.
    A low level language is specific to one machine that is machine dependent. It is machine dependent fast to run but it is not easy to understand.
    A high level language is not specific towards machine that is machine independent it is easy to understand.


Features of C Language

C provide many features i.e.
  • Simple
  • Machine independent or portable
  • Mid-level programming language
  • Structured programming language
  • Rich library 
  • Memory management
  • Fast speed
  • Pointers
  • Recursion
  • Extendable

i. Simple:

    C is a simple language in the sense that is provide a structure approach (to break the problem into parts). The rich set of library functions data types etc.

ii. Portable or Machine independent:

    Unlike assembly language C program can be executed on different machines with some machine specific changes. Therefore C is a machine independent language.

iii. Mid-level Programming language:

    Although C is intended to do low level Programming. It is used to developed System applications such as OS, Kernel, drives etc. It also support the features of a high level language that's why it is known as mid level language

iv. Structure Programming language:

    C is a structure programming language in the sense of that we can break the program into parts using functions, so it is easy to understand and modify.

v. Rich library:

    C Provides a lot of inbuilt functions that make the development fast. It also provides a lot of library functions.

vi. Memory Management:

    It support the features of dynamic memory allocation. In C language we can free the allocated memory at any time by calling the free function.

vii. speed:

    The compilation and execution time of C language is fast since there are lesser inbuilt function and hence the lesser overhead.

viii. Pointers:

    C provides the features of pointers we can directly interact with the memory by using the pointer.

ix. Recursion:

    In C we can called the function within the function which is called recursion. It provides code re-usability for every functions.

x. Extendable:

    C language is extendable because it can easily adopt new features.

Friday, December 13, 2019

Introduction to Programming language



  • A language that is acceptable by the computer system is called a computer language or programming language.It is a medium of communication between the computer & user.
  • A programming language is composed of a set of instruction i.e. understandable to the programmer and recognizable by a computer.The way of writing instruction in such a language is called programming or coding.
  • All computer language can be broadly classified into the following three main categories i.e.
            (a). Machine Level Language
            (b). Assembly Level Language
            (c). High Level Language

A.Machine Level Language:

- This is a sequence of instruction written in binary numbers consisting of 1's & 0's, which is computer can understand directly. Hence this is called as the computer's own language.
- This is a low level language and is consider to be the 1st generation language(1GL).

Advantages

  • It is faster in execution since the computer directly start executive it.
  • It is machine independent.
  • It is difficult to write a program in machine level language.
  • programmer feels very difficult to remember the opcode and to keep the track of the storage location of data and instruction so programming errors are found.
  • It is very difficult to modify the program written in this language.
- To over come these difficulties assembly language developed which is easier then machine level language and easy to perform a task.

B.Assembly Level Language:

- When symbols such as letters ,digits or special character are employed for the operation,operand and other representation is called the assembly language program.
- Such representation are use instead of binary code. As the program written with such codes forms an assembly language program.
- This is consider to be a 2nd generation language(2GL).
- Machine & Assembly language are refereed to as low-level languages.Since the codding for a problem is at the individual instruction level.
- Each computer has its own assembly language that is depend upon the internal architecture processor.
- An assembler is a translator  that text input in the form of the assembly language program and produces machine language code as it's output. 
- An assembly language program cannot be executed by a machine directly as it is not in a binary machine language form.
- An assembler is needed to translate an assembly language program in to the object code which can be executed by the machine. 

Advantages

  • It is easier to understand and convenient for user due to the use of symbols.
  • It is easier locate and correct error and easier to modify.
  • Here the programmer not worried above the storage location of the data.
Disadvantages
  • It is specific to particular machine architecture.
  • since assembly language is machine dependent and assembly language programmer must have knowledge of hardware.
  • It is not portable in nature.
Again it creates a difficulty for performed certain task, to handle such problem high level language was developed.

C.High Level Language:

- High level languages were designed to overcome the limitations of the low level programming languages.
- COBOL,FORTRAN and BASIC are some of the example of high level programming languages.
- High level language are also called 3rd generation language(3GL).
- Since a high level source program must be translated first into the form which is machine can understand this is done by software called compiler.
- Compiler text the source called as input and produces the machine understandable code of the machine as output on which it is to be executed.

Advantages

  • Readability:- Program written in these languages are more readable than these written in assembly and machine language.
  • Portability:- High level programming language can be run on different machines with little or no change.
  • Easy debugging:- Errors can be easily detected and removable.
  • Easy in the development of software:- Since the commands of these programming languages are closer to the English language software can be developed easily by using such programming languages.
Disadvantages
  • Less flexibility:- These languages are less flexible then assembly languages because they don't normally have instructions or mechanism to control the computers,CPU,memory & register.
  • Lower efficiency:- It has lower efficiency then one written in assembly languages or machine languages then we have fourth generation languages.

Fourth generation languages(4GL):

- Fourth generation language are not as clearly defined as other earlier generation. Most people feel that a 4GL as a high level languages that requires significantly fewer instruction to accomplish a particular task that a 3GL done.
- Thus a programmer should be able to write a program faster then in 3rd generation language.
Advantages
  • System development is faster.
  • It is easy to maintain the program.
  • End users can offend can developed their own applications.
  • Program productivity enhanced.

Fifth generation language(5GL):

- In fifth generation programming language natural language plays a vital role.
- It is very much similar to query languages.
- The text of a natural language statement resembles human speech closely.

Thursday, December 12, 2019

CONTENTS

CONTENTS



UNIT-1
Introduction:Introduction to Programming Language,Introduction to C Programming, Keywords & Identifiers, Constant, Variables, Input and Output Operations, Compilation and pre-processing, Data type:Different data types, Data type qualifier, modifiers, Memory representation, size & range, Operators:       Operators (Arithmetic, Relational, Logical, Bitwise, Assignment & Compound assignment, Increment & Decrement, Conditional), Operator types(Unary,Binary,Ternary). Expressions, Order of expression (Precedence & Associativity)
Control structure: Decision Making and Branching (Simple IF Statement, IF...ELSE Statement, Nesting IF...ELSE Statement, ELSE IF Ladder), Selection control structure(Switch Statement).

UNIT-2
Loops:The WHILE Statement, The DO…WHILE Statement, The FOR Statement, Jumps in Loops, Array: Concept of Array, Array Declaration, types of array (one and multiple dimension), Character Arrays and Strings, Subscript and pointer representation of array, Array of Pointers, Limitation of array, Pointers:  Concept of Pointer  (null pointer, wild pointer, dangling pointer, generic pointer),  Pointer Expressions, Accessing the Address of a Variable, Declaring Pointer Variables, Initializations of Pointer Variable, Accessing a Variable through its Pointer, Pointer arithmetic. 

UNIT-3
Storage class: Types (auto, register, static, extern), scope rules, declaration and definition. Function: Function & types (User defined function, library function) Function Definition, Declaration, Function Calls, Header file and library, Function Arguments, string handling function (strlen, strcmp, strcpy, strncpy, strcat, strstr), Function recursion, Functions Returning Pointers, Pointers to Functions, Command line arguments, Application of pointer (dynamic memory allocation).

UNIT-4 
Structure and Union: Defining, Declaring, Accessing, Initialization Structure, nested structure, self-referential structure, bit-field, Arrays of Structures, Structures and Functions, Unions, difference between structure and union, active data member, structure within union, Self-referential Structure. 
File: File Management in C, Defining and Opening a File, File opening modes (read, write, append), Closing a File, File operations, file and stream, Error Handling During  I/O Operations, sequential and random access file, low level and high level file.