Everything you do now is for your future. Think About that.
--Your friends at LectureNotes

C Language

by Aman KumarAman Kumar
Type: NoteOffline Downloads: 2Views: 64Uploaded: 15 days ago

Share it with your friends

Suggested Materials

Leave your Comments


Aman Kumar
Aman Kumar
C - LANGUAGE Class 1: Inroduction: 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. The UNIX operating system, the C compiler, and essentially all UNIX applications programs have been written in C. The 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 platform Compile & Execute C Program: Lets look at how to save the source code in a file, and how to compile and run it. Following are the simple steps: 1. Open a text editor and add the above-mentioned code. 2. Save the file as hello.c 3. Open a command prompt and go to the directory where you saved the file. 4. Type gcc hello.c and press enter to compile your code. 5. If there are no errors in your code the command prompt will take you to the next line and would generate a.out executable file. 6. Now, type a.out to execute your program.
7. You will be able to see "Hello World" printed on the screen Structure of c programm :C Hello World Example A C program basically consists of the following parts: • Preprocessor Commands • Functions • Variables • Statements & Expressions • Comments Let us look at a simple code that would print the words "Hello World": #include <stdio.h> int main() { /* my first program in C */ printf("Hello, World! \n"); return 0; } Let us look various parts of the above program: • The first line of the program #include <stdio.h> is a preprocessor command, which tells a C compiler to include stdio.h file before going to actual compilation. • The next line int main() is the main function where program execution begins. • The next line /*...*/ will be ignored by the compiler and it has been put to add additional comments in the program. So such lines are called comments in the program. • The next line printf(...) is another function available in C which causes the message "Hello, World!" to be displayed on the screen. • The next line return 0; terminates main()function and returns
the value 0. Print Function : The C library function int printf() sends formatted output to stdout. Declaration Following is the declaration for printf() function. int printf(); Comments in C language: In programming, comments are used to described the workintg of the code. compiler ignore the line which are written in a comment. There are two types of comment in 'C'1.Single line Comment: // this is used for to declare single line comment. 2.Multi line Comment: /*This type of comment is used to declare multiple line of comment*/ Class 2: Introduction to C block of statement: C has three types of statement1. Assignment ( = ) 2. Selection (Branching): • if(expression) • else • switch 3. Iteration (Looping)
• While • for • do Blocks: These statement are grouped in to blocks, a blocks is identified by curly brackets. there are two types od Blocks: 1. Statement blocks: if(i==j) { printf("|n martin \n"); } 2.Function Blocks: int add(int a,int b) { int c; c=a+b; return c; } Displaying Data: Displaying data means graph representation of any program:

Lecture Notes