Docsity

Basic Of C Programing language, Schemes and Mind Maps of Programming Languages

Toggle sidebar
bg1
Theory Notes - Basics of C
introduction to c
The C Language is developed for creating system applications that direct interacts to the
hardware devices such as drivers, kernals etc.
C programming is considered as the base for other programming languages, that is why it is
known as mother language.
It can be defined by following ways:
1. Mother language
2. System programming language
3. Procedure-oriented programming language
4. Structured programming language
5. Mid level programming language
1) C as a mother language
C language is considered as the mother language of all the modern languages because most of
the compilers, JVMs, Kernals etc. are written in C language and most of languages follows c
syntax e.g. C++, Java etc.
It provides the core concepts like array, functions, file handling etc. that is being used in many
languages like C++, java, C# etc.
2) C as a system programming language
A system programming language is used to create system softwares. C language is a system
programming language because itcan be used to do low level programming (e.g. driver and
kernel). It is generally used to create hardware devices, OS, drivers, kernels etc. For example,
linux kernel is written in C.
It can't be used in internet programming like java, .net, php etc.
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Basic Of C Programing language and more Schemes and Mind Maps Programming Languages in PDF only on Docsity!

Theory Notes - Basics of C

introduction to c

The C Language is developed for creating system applications that direct interacts to the hardware devices such as drivers, kernals etc. C programming is considered as the base for other programming languages, that is why it is known as mother language. It can be defined by following ways:

  1. Mother language
  2. System programming language
  3. Procedure-oriented programming language
  4. Structured programming language
  5. Mid level programming language
  1. C as a mother language C language is considered as the mother language of all the modern languages because most of the compilers, JVMs, Kernals etc. are written in C language and most of languages follows c syntax e.g. C++, Java etc. It provides the core concepts like array, functions, file handling etc. that is being used in many languages like C++, java, C# etc.
  2. C as a system programming language A system programming language is used to create system softwares. C language is a system programming language because it can be used to do low level programming (e.g. driver and kernel). It is generally used to create hardware devices, OS, drivers, kernels etc. For example, linux kernel is written in C. It can't be used in internet programming like java, .net, php etc.
  1. C as a procedural language A procedure is known as function, method, routine, subroutine etc. A procedural language specifies a series of steps or procedures for the program to solve the problem. A procedural language breaks the program into functions, data structures etc. C is a procedural language. In C, variables and function prototypes must be declared before being used.
  2. C as a structured programming language A structured programming language is a subset of procedural language. Structure means to break a program into parts or blocks so that it may be easy to understand. In C language, we break the program into parts using functions. It makes the program easier to understand and modify.
  3. C as a mid-level programming language C is considered as a middle level language because it supports the feature of both low-level and high level language. C language program is converted into assembly code, supports pointer arithmetic (low level), but it is machine independent (feature of high level). Low level language is specific to one machine i.e. machine dependent. It is machine dependent, fast to run. But it is not easy to understand. High Level language is not specific to one machine i.e. machine independent. It is easy to understand. C programming language was developed in 1972 by Dennis Ritchie at bell laboratories of AT&T (American Telephone & Telegraph), located in U.S.A.

Features of c

  1. Simple C is a simple language in the sense that it provides structured approach (to break the problem into parts), rich set of library functions , data types etc.
  2. Machine Independent or Portable Unlike assembly language, c programs can be executed in many machines with little bit or no change. But it is not platform-independent.
  3. Mid-level prorgramming language C is also used to do low level programming. It is used to develop system applications such as kernel, driver etc. It also supports the feature of high level language. That is why it is known as mid-level language.
  4. Structured prorgramming language C is a structured programming language in the sense that we can break the program into parts using functions. So, it is easy to understand and modify.
  5. Rich Library C provides a lot of inbuilt functions that makes the development fast.
  6. Memory Management It supports the feature of dynamic memory allocation. In C language, we can free the allocated memory at any time by calling the free() function.
  7. Speed The compilation and execution time of C language is fast.
  1. Pointer C provides the feature of pointers. We can directly interact with the memory by using the pointers. We can use pointers for memory, structures, functions, array etc.
  2. Recursion In c, we can call the function within the function. It provides code reusability for every function.
  3. Extensible C language is extensible because it can easily adopt new features.

First C Program

To write the first c program, open the C console and write the following code: #include #include void main() { clrscr(); printf("Hello C Language"); getch(); } **#include ** includes the standard input output library functions. The printf() function is defined in stdio.h. **#include ** includes the console input output library functions. The getch() function is defined in conio.h file. void main() The main() function is the entry point of every program in c language. The void keyword specifies that it returns no value. printf() The printf() function is used to print data on the console. clrscr() The clrscr() functionis used to clear the console screen.

Output enter a number: cube of number is: The scanf("%d",&number) statement reads integer number from the console and stores the given value in number variable. The printf("cube of number is:%d ",numbernumbernumber)** statement prints the cube of number on the console.

variables in c

A variable is a name of memory location. It is used to store data. Its value can be changed and it can be reused many times. It is a way to represent memory location through symbol so that it can be easily identified. Let's see the syntax to declare a variable:

  1. dataType variable_list; The example of declaring variable is given below:
  2. int a;
  3. float b;
  4. char c; Here, a, b, c are variables and int,float,char are data types. We can also provide values while declaring the variables as given below:
  5. int a=10,b=20;//declaring 2 variable of integer type
  6. float f=20.8;
  7. char c='A'; There are many types of variables in c: 1. local variable 2. global variable
  1. static variable
  2. automatic variable
  3. external variable Local Variable A variable that is declared inside the function or block is called local variable. It must be declared at the start of the block. void function1() { int x=10;//local variable } You must have to initialize the local variable before it is used. Global Variable A variable that is declared outside the function or block is called global variable. Any function can change the value of the global variable. It is available to all the functions. It must be declared at the start of the block. int value=20;//global variable void function1() { int x=10;//local variable } Static Variable A variable that is declared with static keyword is called static variable. It retains its value between multiple function calls. void function1() { int x=10;//local variable static int y=10;//static variable

Data Types in c

A data type specifies the type of data that a variable can store such as integer, floating, character etc. There are 4 types of data types in C language. Types Data Types Basic Data Type int, char, float, double Derived Data Type array, pointer, structure, union Enumeration Data Type enum Void Data Type void

  • The memory size of basic data types may change according to 32 or 64 bit operating system. Type Size int 2 bytes long int 4 bytes float 4 bytes double 8 bytes

char 1 byte

Keywords in c

A keyword is a reserved word. You cannot use it as a variable name, constant name etc. There are only 32 reserved words (keywords) in C language. A list of 32 keywords in c language is given below: auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while

operators in c

An operator is simply a symbol that is used to perform operations. There can be many types of operations like arithmetic, logical, bitwise etc. There are following types of operators to perform different types of operations in C language.

  • Arithmetic operators
  • Relational operators
  • increment/decrement operators
  • Logical operators
  • Bitwise operators
  • Ternary or Conditional Operators
  • Assignment Operator
  • Misc Operator or Special operators

Bitwise XOR ^ Left to right Bitwise OR | Left to right Logical AND && Left to right Logical OR || Left to right Conditional ?: Right to left Assignment = += - = *= /= %=>>= <<= &= ^= |= Right to left Comma , Left to right