Written Report SP
Written Report SP
Written Report SP
LANGUAGE
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
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.
=> 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.
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.
=> 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.
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)
%d is the format specifier. This informs to the compiler that the incoming
value is an integer value.
%c – character
%f – float
%lf – double
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.
In functions we use:-
Function Declaration,
Function Calling,
Function Definition
Example:
#include<stdio.h>
int main()
fun(10); //Call
printf(“%d”,x);
}
ARRAY:
Arrays are collection of homogenous elements which are usually preferred by a
single name.
Syntax:-
datatype name[size]
=>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
=>int l[10][3][2];
e.g
#include<stdio.h>
#include<conio.h>
void main ()
int s[10],p;
Scanf (“%d”,&s[p]);
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] ;
if ( fp == NULL )
{
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;
};
It is accessed as:-
sname.vname
example:
struct book1
char book[30];
int pages;
float price;
};
clrscr();
printf(“\nBook: %d”,sizeof(bk1.book));
printf(“\nPages: %d”,sizeof(bk1.pages));
printf(“\nBook:%d”,sizeof(bk1.price));
printf(“\nBook:%d”,sizeof(bk1));
THANKS