Written Report SP

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

WRITTEN REPORT ON ‘C’

LANGUAGE

BY- SHIVAM PRAKASH


F1002
A18
11007152
ORIGIN:
The C programming language was designed by Dennis Ritchie at Bell Laboratories
in 1972. C is a structured programming language. It is currently the most
commonly-used language for embedded systems. It is basically evolved from B,
which evolved from BCPL. Comments in C provide us easy readability.

C is a general-purpose computer programming language developed between 1969


and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with
the UNIX operating system.
Although C was designed for implementing system software, it is also widely used
for developing portable application software.
C is one of the most popular programming languages of all time and there are very
few computer architectures for which a C compiler does not exist. C has greatly
influenced many other popular programming languages, most notably C++, which
began as an extension to C.

INTRODUCTION:
C language is used as mostly used programming language. C’s ability to
communicate directly with hardware makes it a powerful choice for system
programmers. In fact, popular operating systems such as UNIX and Linux are
written entirely in C. Additionally, even compilers and interpreters for other
languages such as FORTRAN, Pascal, and BASIC are written in C. However, C’s
scope is not just limited to developing system programs. It is also used to develop
any kind of application, including complex business ones. The following is a
partial list of areas where C language is used: 

Ø       Embedded Systems  

Ø       Systems Programming

Ø       Artificial Intelligence

Ø       Industrial Automation

Ø       Computer Graphics
Ø       Space Research

Ø       Image Processing

Ø       Game Programming 

C is a structured programming language, which means that it allows you to


develop programs using well-defined control structures(you will learn about
control structures in the articles to come), and provides  modularity (breaking the
task into multiple sub tasks that are simple enough to understand and to reuse). 

C is often called a middle-level language because it combines the best elements of


low-level or machine language with high-level languages. 

‘C’ CHARACTER SET:


A character denotes any alphabet, digit or symbols to represent information. The
following are the valid alphabets, numbers and special symbols permitted in C 
Numerals: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 
Alphabets: a, b ….z
                  A, B ...Z 
 
Arithmetic Operations: +, -, *, /, %( Mod) 
Special Characters:
                               
( ) { } [ ] < >
= ! $ ? . , : ;
‘ “ & | ^ ~ ` #
\ Blank - _ / * % @
 

CONSTANTS, VARIABLES:
A ‘constant’ is an entity that does not change, but a ‘variable’ as the name
suggests may change. We do a number of calculations in a computer and the
computed values are stored in some memory spaces. In order to retrieve and
re-use those values from the computer’s memory locations they are given
names. Since the value stored in each location may change, the names given to
these locations are called as ‘variable names’.

Constants:
There are mainly three types of constants namely:
Integer, real and character constants.

KEYWORDS:
Keywords are the certain reserved words.

=> They have standard, predefined meanings in C.

=> These can be used only for their intended purpose; they can’t be used as
programmer-defined identifiers.

C makes use of only 32 keywords or reserved words which combine with the
formal syntax to the form the C programming language. Note that all keywords
in C are written in lower case. A keyword may not be used as a variable name.

Auto double int Struct


break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if  static while 
 
 
IDENTIFIERS:
Identifiers are names that are given to various program elements, such as variables,
functions, and arrays.

The first character in an identifier must be a letter or the _ (underscore) character;


however, beginning identifiers with an underscore is considered poor programming
style.

The compiler distinguishes between uppercase and lowercase letters in identifiers.


For example, PROFIT and profit represent different identifiers. If you specify a
lowercase a as part of an identifier name, you cannot substitute an uppercase A in
its place; you must use the lowercase letter.

The universal character names for letters and digits outside of the basic source
character set are allowed in C++ and at the C99 language level, under compilation
with the c99 invocation command, the -qlanglvl=extc99 or -
qlanglvl=stdc99 options or related programs (for C), or the-qlanglvl=ucs   option.

The rules for the construction is you may use the 52 upper and lower case
alphabetic characters, the 10 digits and finally the underscore ‘_’, which is
considered to be an alphabetic character for this purpose. The only restriction is
the usual one; identifiers must start with an alphabetic character

HEADERFILES:
C header files are used to provide a way of telling the compiler what interface
specific functions require in order to be used.

 These files allow programmers to separate certain elements of a program's source


code into reusable files. Header files commonly contain forward
declarations of classes, subroutines, variables, and other identifiers. Programmers
who wish to declare standardized identifiers in more than one source file can place
such identifiers in a single header file, which other code can then include whenever
the header contents are required. This is to keep the interface in the header separate
from the implementation. The C standard library and C++ standard
library traditionally declare their standard functions in header files.

=> The files that are specified in the include section is called as header file
=>These are precompiled files that have some functions defined in them.

=> Some examples of headerfiles are:-

 string.h: for string handling

 stdio.h: standardized input and output

 math.h: mathematical functions

 ctype.h: character types etc.

I/O FUNCTION:
To Input we use:

 scanf(“%d”,&a);

 Gets an integer value from the user and stores it under the name “a”

To Output we use:

 printf(“%d”,a)

 Prints the value present in variable a on the screen

 %d is the format specifier. This informs to the compiler that the incoming
value is an integer value.

 Other data types can be specified as follows:

 %c – character

 %f – float

 %lf – double

 %s – character array (string)

 Printf and scanf are defined under the header file stdio.h
FUNCTIONS:
A function is a self-contained block of statements that perform some kind of task.

Functions enable easy maintainability of code,

By breaking large file into smaller modules.

In functions we use:-

Function Declaration,

Function Calling,

Function Definition

Example:

#include<stdio.h>

void fun(int a); //declaration

int main()

fun(10); //Call

void fun(int x) //definition

printf(“%d”,x);

}
ARRAY:
Arrays are collection of homogenous elements which are usually preferred by a
single name.

Syntax:-

datatype name[size]

=>int a[10]; means space for ten integers.

=>The address of a is not stored in memory: the compiler inserts code to compute
it when it appears.

=>Ritchie calls this interpretation the biggest conceptual jump from BCPL to C

=> Array declarations read right-to-left

=>int l[10][3][2];

=>“an array of ten arrays of three arrays of two ints”

=>We access array with the help of loop.

e.g

#include<stdio.h>

#include<conio.h>

void main ()

int s[10],p;

Printf(“Enter array elements”);

For (p=0; p<9; p++)

Scanf (“%d”,&s[p]);

Printf (“You entered”);


For (i=0;i<9;i++)

Scanf (“%d”,s[p]);

Getch():

FILE HANDLING:
File handling means to handle files using language.
 There are different operations that can be carried out on a file.
These are:
 Creation of a new file
 Opening an existing file
 Reading from a file
 Writing to a file
 Moving to a specific location in a file (seeking)
 Closing a file
Example:-

#include <stdio.h>

void main( )

FILE *fp ;

char s[80] ;

fp = fopen ( "POEM.TXT", "w" ) ;

if ( fp == NULL )
{

puts ( "Cannot open file" ) ;

printf ( "\nEnter a few lines of text:\n" ) ;

while ( strlen ( gets ( s ) ) > 0 )

fputs ( s, fp ) ;

fputs ( "\n", fp ) ;

fclose ( fp ) ;

STRUCTURE:
A Structure is a Group of data items of different data types held together in a single
unit. In some programming contexts, you need to access multiple data types under
a single name for easier data manipulation; for example you want to refer to
address with multiple data like house number, street, zip code, country. C supports
structure which allows you to wrap one or more variables with different data types.
A structure can contain any valid data types like int, char, float even arrays or even
other structures. Each variable in structure is called a structure member.

Syntax:-

struct sname

{ type var1;

type var2;

type var3;

.
.

type varN;

};

Struct sname strvar;

It is accessed as:-

sname.vname

example:

struct book1

char book[30];

int pages;

float price;

};

struct book1 bk1;

clrscr();

printf(“\nSize of Structure elements\n”);

printf(“\nBook: %d”,sizeof(bk1.book));

printf(“\nPages: %d”,sizeof(bk1.pages));

printf(“\nBook:%d”,sizeof(bk1.price));

printf(“\nBook:%d”,sizeof(bk1));

THANKS

You might also like