Posts

History of C

C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC PDP-11 computer in 1972. In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available description of C, now known as the K&R standard. The UNIX operating system, the C compiler, and essentially all UNIX application programs have been written in C. C has now become a widely used professional language for various reasons − Easy to learn Structured language It produces efficient programs It can handle low-level activities It can be compiled on a variety of computer platforms Facts about C C was invented to write an operating system called UNIX. C is a successor of B language which was introduced around the early 1970s. The language was formalized in 1988 by the American National Standard Institute (ANSI). The UNIX OS was totally written in C. Today C is t

C can also be defined has

C can be defined by the following ways: Mother language System programming language Procedure-oriented programming language Structured programming language Mid-level programming language 1) C as a mother language C language is considered as the mother language of all the modern programming languages because  most of the compilers, JVMs, Kernels, etc. are written in C language , and most of the programming languages follow C syntax, for example, C++, Java, C#, etc. It provides the core concepts like the array, strings, functions, file handling, etc. that are 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 software. C language is a system programming language because it  can be used to do low-level programming (for example driver and kernel) . It is generally used to create hardware devices, OS, drivers, kernels, etc. For example, Linux kernel is writt

Features of C Language

Image
Features of C Language C is the widely used language. It provides many  features that are given below. Simple Machine Independent or Portable Mid-level programming language structured programming language Rich Library Memory Management Fast Speed Pointers Recursion Extensible 1) Simple C is a simple language in the sense that it provides a  structured approach  (to break the problem into parts),  the rich set of library functions ,  data types , etc. 2) Machine Independent or Portable Unlike assembly language, c programs  can be executed on different machines  with some machine specific changes. Therefore, C is a machine independent language. 3) Mid-level programming language Although, C is  intended to do low-level programming . It is used to develop system applications such as kernel, driver, etc. It  also supports the features of a high-level language . That is why it is known as mid-level language. 4) Structured programming language C is a stru

First C Program

Image
First C Program Before starting the abcd of C language, you need to learn how to write, compile and run the first c program. To write the first c program, open the C console and write the following code: #include <stdio.h>      int  main(){     printf( "Hello C Language" );     return  0;    }   #include <stdio.h>  includes the  standard input output  library functions. The printf() function is defined in stdio.h . int main()  The  main() function is the entry point of every program  in c language. printf()  The printf() function is  used to print data  on the console. return 0  The return 0 statement, returns execution status to the OS. The 0 value is used for successful execution and 1 for unsuccessful execution. How to compile and run the c program There are 2 ways to compile and run the c program, by menu and by shortcut. By menu Now  click on the compile menu then compile sub menu  to compile the c program. Then  click

Flow of C program

Image
Flow of C Program The C program follows many steps in execution. To understand the flow of C program well, let us see a simple program first. File: simple.c #include <stdio.h>      int  main(){     printf( "Hello C Language" );     return  0;    }   Execution Flow Let's try to understand the flow of above program by the figure given below. 1) C program (source code) is sent to preprocessor first. The preprocessor is responsible to convert preprocessor directives into their respective values. The preprocessor generates an expanded source code. 2) Expanded source code is sent to compiler which compiles the code and converts it into assembly code. 3) The assembly code is sent to assembler which assembles the code and converts it into object code. Now a simple.obj file is generated. 4) The object code is sent to linker which links it to the library such as header files. Then it is converted into executable code. A simple.exe file is gen

printf() scanf()

printf() and scanf() in C The printf() and scanf() functions are used for input and output in C language. Both functions are inbuilt library functions, defined in stdio.h (header file). printf() function The  printf() function  is used for output. It prints the given statement to the console. The syntax of printf() function is given below: printf( "format string" ,argument_list);   The  format string  can be %d (integer), %c (character), %s (string), %f (float) etc. scanf() function The  scanf() function  is used for input. It reads the input data from the console. scanf( "format string" ,argument_list);   Program to print cube of given number Let's see a simple example of c language that gets input from the user and prints the cube of the given number. #include<stdio.h>      int  main(){     int  number;     printf( "enter a number:" );     scanf( "%d" ,&number);     p

variables in c

Variables in C A  variable  is a name of the 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: type variable_list;   The example of declaring the variable is given below: int  a;   float  b;   char  c;   Here, a, b, c are variables. The int, float, char are the data types. We can also provide values while declaring the variables as given below: int  a=10,b=20; //declaring 2 variable of integer type    float  f=20.8;   char  c= 'A' ;   Rules for defining variables A variable can have alphabets, digits, and underscore. A variable name can start with the alphabet, and underscore only. It can't start with a digit. No whitespace is allowed within the variable name. A variable name must not be any reserved word or keyword, e.