They know who you are. Show them what you can be.
--Your friends at LectureNotes

Note for Programming in C - C By SARMI SASIREKHA

  • Programming in C - C
  • Note
  • 4 Topics
  • 289 Offline Downloads
  • Uploaded 2 years ago
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-1

Back​ ​to​ ​notes​ ​section​ ​: NOTES​ ​FOR​ ​C​ ​LANGUAGE​ ​PART​ ​1 What​ ​is​ ​Complier? Compiler is a program that converts the source code (program written in a language other than machine language ) in to machine code. Computer can understand machine code and execute machine code​. Therefore we can state that compiling is a process of converting source code to machine code if​ ​source​ ​code​ ​is​ ​error​ ​free. What​ ​is​ ​the​ ​basic​ ​structure​ ​of​ ​c​ ​program? Consider​ ​a​ ​simple​ ​program #include​ ​<stdio.h> #include​ ​<conio.h> void​ ​main() { int​ ​a,b; printf(“\n​ ​enter​ ​two​ ​values”); scanf(“%d​ ​%d”,&a,&b); c=a+b; printf(“\n​ ​addition=%d”,c); getch(); } We​ ​can​ ​note​ ​following​ ​facts: 1.​ ​Program​ ​starts​ ​with​ ​#include #include is known as preprocessor directive. This preprocessor directive gives instruction to preprocessor program to include contents of file mentioned in angle bracket (or in double quotes) to our source file. The file name in angle bracket is known as include file (because this is used always with include preprocessor) or header file (appears in head/top position of file). This header files​ ​contents​ ​macro,​ ​constant​ ​and​ ​function​ ​declaration. 2.​ ​void​ ​main() void​ ​specifies​ ​function​ ​does​ ​not​ ​return​ ​value. ‘main’ is a function which acts as entry point from which our program statement starts​ ​running.​ ​Declaration​ ​statement​ ​is​ ​followed​ ​by​ ​executable​ ​statements.

Text from page-2

3.​ ​Blank​ ​spaces​ ​may​ ​be​ ​inserted​ ​to​ ​increase​ ​readability. 4.​ ​Usually​ ​all​ ​statements​ ​are​ ​entered​ ​in​ ​lowercase 5.​ ​We​ ​can​ ​start​ ​writing​ ​statement​ ​from​ ​any​ ​column​ ​position. 6.​ ​Any​ ​‘C’​ ​statement​ ​terminates​ ​by​ ​semicolon; Write​ ​program​ ​to​ ​swap​ ​two​ ​values. (a)​ ​using​ ​a​ ​third​ ​variable. #include<stdio.h> #include<conio.h> void​ ​main() { int​ ​a=3,b=4,c; c=a; a=b; b=c; printf(“\n​ ​a=%d,b=%d”,a,b); getch(); } (b)without​ ​using​ ​a​ ​third​ ​variable. #include<stdio.h> #include<conio.h> void​ ​main() { int​ ​a=3,b=4; a=a+b; b=a-b; a=a-b; printf(“\n​ ​a=%d,b=%d”,a,b); getch(); } What​ ​does​ ​void​ ​means​ ​in​ ​front​ ​of​ ​main()? void means function is not going to return a value. If we remove void we have to

Text from page-3

use​ ​‘return​ ​0;’​ ​statement​ ​before​ ​closing​ ​brace​ ​of​ ​main​ ​function. Why​ ​do​ ​we​ ​use​ ​getch()​ ​before​ ​closing​ ​brace​ ​of​ ​main​ ​function? getch() is a library function which can input a character from user. Using getch() before closing brace of main lets us read program output by halting the output window. If we do not give getch() then we must use alt+f5 key combination to read program output because we will return to source code window as soon as program​ ​completes. Can​ ​we​ ​write​ ​inclusion​ ​of​ ​header​ ​file​ ​in​ ​any​ ​order? Yes,​ ​we​ ​can​ ​include​ ​header​ ​file​ ​in​ ​any​ ​order. What​ ​is​ ​the​ ​difference​ ​between​ ​#include<stdio.h>​ ​and​ ​#include​ ​”stdio.h”? #include <stdio.h> tells the preprocessor to search the header file in the directory mentioned in integrated development environment only and insert the contents​ ​of​ ​header​ ​file​ ​in​ ​source​ ​file. #include “stdio.h” tells the preprocessor to search the header file in the directory in which source code lies and if header file not found in the directory where source code lies then search the header file in the directory mentioned in integrated development environment and finally insert the contents of header file​ ​in​ ​source​ ​file. What​ ​is​ ​linking/​ ​why​ ​do​ ​we​ ​need​ ​linking​ ​after​ ​compiling? Linking is a process which runs after compiling process to combine several dependent machine codes (object code) into a single executable code. The program​ ​which​ ​performs​ ​the​ ​linking​ ​process​ ​is​ ​known​ ​as​ ​linker. What is preprocessor?/Write short notes on preprocessor or list different preprocessor Preprocessor is a program which works before compiling process. It follows the instruction given by preprocessor directives. After preprocessor has finished its work​ ​compiling​ ​process​ ​begins. Preprocessor directive begins with # because this instructs the preprocessor what is followed is not an ordinary ‘​ c’ statement but a preprocessor​ ​directive. e.g.​ ​#include​ ​<stdio.h> This tells the preprocess program to insert contents of stdio.h file into current

Text from page-4

source​ ​file​ ​(program​ ​written​ ​in​ ​high​ ​level​ ​language). Some​ ​preprocessor​ ​are: #include,​ ​#define,​ ​#ifdef,​ ​#ifndef,​ ​#undef,​ ​#else,​ ​#endif,​ ​#pragma​ ​etc. What​ ​are​ ​the​ ​popular​ ​features​ ​of​ ​‘C’​ ​language? The​ ​features​ ​are: 1.​ Portability: This refers to the ability of a program to run in different environments. Different environments could refer to different computers, operating systems, or different compilers. Since ‘C’ language is mid level language and its compiler is available for variety of environments we can say it​ ​is​ ​portable. 2.​ ​ ​Flexibility:​ ​‘c’​ ​language​ ​is​ ​flexible​ ​because: (a)​ ​It​ ​provides​ ​facility​ ​of​ ​creating​ ​user​ ​defined​ ​data​ ​type. (b) It is not necessary to write statement in ‘c’ in a particular format which means​ ​we​ ​can​ ​start​ ​writing​ ​statement​ ​in​ ​‘c’​ ​from​ ​any​ ​column. 3.​ Mid level language: C is a mid level language combines feature of high level language (faster code development) and low level language (efficient program). 4.​ ​ ​Wide​ ​acceptability:​ ​Majority​ ​of​ ​people​ ​know​ ​‘C’​ ​language. 5.​ System Programming: system programming and application programming using​ ​‘C’​ ​language​ ​are​ ​possible. What​ ​is​ ​an​ ​IDE? An IDE is nothing else but it is a program which includes all facilities to develop and​ ​run​ ​program,​ ​such​ ​as​ ​editor,​ ​compiler,​ ​debugger​ ​and​ ​so​ ​on. What​ ​is ​ ​C? C is a programming language developed at AT & B bell lab. of USA in 1972. It was developed by Dennis Ritchie. It is user friendly, general purpose and reliable language. How​ ​C​ ​originated?​ ​Or​ ​Write​ ​short​ ​notes​ ​on​ ​history​ ​of​ ​C​ ​language. By 1960 a hoard of computer language had come into existence almost each for a specific purpose. An International committee was setup to develop a general purpose language using which any type of application can be developed easily and the outcome of the effort was Alogol-60. Algol-60 did not become popular because of its abstract nature and many complicated features. Combined

Lecture Notes