Professional Documents
Culture Documents
Notes of Computer Language
Notes of Computer Language
C is a base for the programming. If you know 'C,' you can easily grasp the
knowledge of the other programming languages that uses the concept of 'C'.
modules. Each module can be written separately and together it forms a single 'C'
program. This structure makes it easy for testing, maintaining and debugging
processes.
'C' contains 32 keywords, various data types and a set of powerful built-in functions
Another feature of 'C' programming is that it can extend itself. A 'C' program contains
various functions which are part of a library. We can add our features and functions
to the library. We can access and use these functions anytime we want in our
program. This feature makes it simple while working with complex programming.
Various compilers are available in the market that can be used for executing
It is a highly portable language which means programs written in 'C' language can
run on other machines. This feature is essential if we wish to use or execute the
Elements of C-Language
Variables: These will how data is represented. It can range from something very
simple, such as the age of a person, to something very complex, such as a record of
university students holding their names, ages, addresses, what courses they have
Constant: The values, which are used in program and remain the same during
number of times.
whether or not some condition is satisfied. These type of statement used different
Input/Output: This will allow interaction of the program with external entities. This
files.
Subroutines and functions: This will allow you to put oft-used snippets of code into
one location, which can then be used over and over again.
A constant value is the one, which does not change during the execution of a
1. Integer Constants
2. Real Constants
4. String Constants
Defining Constants
Preprocessor Directive are the lines included in program with the character# which
make them different from the normal code. We can use this to declare a constant as
shown below:
Example:
difference is you will have to precede the definition with a const keyword.
Example:
Literals:
The values assigned to each constant variable are referred to as the literals.
For example
Is a constant expression and the value 5 is referred to as constant integer literal.
Derived data types are nothing but primary data types but a little twisted or grouped
together like array, structure, union and pointer. These are discussed in details later.
sign. Spaces, commas and non-digit characters are not permitted between digits.
Floating Point data type is used to store the fractional part (Real Number).
Floating Point Data type consist on Float, Double and Long Double
Void type
void type means no value. This is usually used to specify the type of functions which
returns nothing. We will get acquainted to this data type as we start learning more
Although they contain two characters they represent only one character. Given
Escape sequences are typically used to specify actions such as carriage returns and
tab movements on terminals and printers. They are also used to provide literal
meanings, such as the double quotation mark ("). The following list has some the
Constant Meaning
'\b' Backspace
'\0' Null
A variable is a value that can change any time. In computer programming we say
those variables are those memory locations, which are used to store the constant
value. The programmer should carefully choose a variable name so that its use is
reflected in a useful way in the entire program. Variable names are case sensitive.
average1
1. They must always begin with a letter, although some systems permit
There are four basic types of variable in C; they are: char, int, double and float.
char The most basic unit addressable by the machine; typically a single octet(one
int The most natural size of integer for the machine; typically a whole 16, 32 or 64-
Declaration of Variables
You are required to declare your variables before you use them. You do this by
providing a list of variables near the beginning of the program. That way, the
compiler knows what the variables are called and what type of variables they are
(what values they can contain). Officially, this process is known as declaring your
variables.
For example:
int count;
char key;
char lastname[30];
Local Variable: -
When we declare a variable in body of the function this is called local variable. These
types of variable are used only in this function in which these variables are declare.
Global Variables: -
Local variables are declared within the body of a function, and can only be used
use of global variables. They can lead to poor program structure, and tend to clog up
A global variable declaration looks normal, but is located outside any of the
program's functions. This is usually done at the beginning of the program file.
External Variables: -
Where a global variable is declared in one file, but used by functions from another,
Global and external variables can be of any legal type. They can be initialized, but
the initialization takes place when the program starts up, before entry to the main
function.
Static Variables
Another class of local variable is the static type. Static can only be accessed from
the function in which it was declared, like a local variable. The static variable is not
destroyed on exit from the function; instead its value is preserved, and becomes
available again when the function is next called. Static variables are declared as
Static variables can be initialized as normal; the initialization is performed once only,
These are the word, which have special meaning for compiler. These meaning are
do if static while
Operators
Operator are special symbol that perform some special function like that addition,
1) Arithmetic operators
+ Addition
- Suntraction
* Multiplication
/ Division
% (Find Reminder from Integer Division)
force a different order of evaluation to this. Where division is performed between two
integers, the result will be an integer, with remainder discarded. Modulo reduction is
by zero, this will cause an error, usually causing the program to crash.
x+y
x-y
-x + y
(a * b) + c
2) Relational Operators: -
relational operators.
< Less than
> Greater than
== Equal to
! = Not equal to
It is required to compare the marks of 2 students, salary of 2 persons; we can
A simple relational expression contains only one relational operator and takes the
following form.
Where exp1 and exp2 are expressions, which may be simple constants, variables or
combination of them.
10 < 7 + 5 TRUE
&& AND
|| OR
! NOT
evaluate their left hand operand, and then only evaluate the right hand one if this is
required.
These operator return the following result by using different combination:
If we use && operator then both side return must True and both side must be
checked.
But if we use || (OR) Operator then only one side return True Result the Expression
Return True. In this case if left side return true then there is no Need to check the
Right Expression.
4) Assignment Operator: -
X=10 ;
x = (m * n) + c;
In this example first of all expression is evaluated and then result of the expression
save in variable x.
very useful in C language. They are extensively used in for and while loops.
1. ++ variable name
2. variable name++
3. – –variable name
4. variable name– –
The increment operator ++ adds the value 1 to the current value of operand and the
decrement operator – – subtracts the value 1 from the current value of operand. +
+variable name and variable name++ mean the same thing when they form
statements independently, they behave differently when they are used in expression
m = 5;
y = ++m; (prefix)
m = 5;
Then the value of y will be 5 and that of m will be 6. A prefix operator first adds 1 to
the operand and then the result is assigned to the variable on the left. On the other
hand, a postfix operator first assigns the value to the variable on the left and then
The conditional operator consists of 2 symbols the question mark (?) and the colon
(:).
exp1 ? exp2 : exp3
exp1 is evaluated first. If the expression is true then exp2 is evaluated & its value
becomes the value of the expression. If exp1 is false, exp3 is evaluated and its value
becomes the value of the expression. Note that only one of the expression is
evaluated.
For example
a = 10;
b = 15;
x = (a > b) ? a : b
Here x will be assigned to the value of b. The condition follows that the expression is
Expression :-
Operators and values are combined to form expressions. The values produced by
expressions.
We say that collection of operand and operator is called expression. If expression
use logical operator then this is called logical expression. And if expression is used
X +5 (Arithmetic Operator)
Structure of C Program
main()
printf("This is a C program\n");
Though the program is very simple few points are worthy of note.
Every C program must contain a function called main. This is the start point of
the program.
main() declares the start of the function, while the two curly brackets show the
a block.
èEvery function contains some statements and every statement end with
semicolon (;).
printf("This is a C program\n");
Prints the words on the screen. The text to be printed is enclosed in double
quotes. The \n at the end of the text tells the program to print a new line as
Most C programs are in lower case letters. You will usually find upper case
strings.
C is case sensitive, that is, it recognizes a lower case letter and it's upper
Menu.
After writing C-Program first of all compile C-Program and create Object File. For this
If any bugs (error) occur then correct these errors by Editing Option.
Executing C-Program
When program Successfully compile and all the bugs are removed then
In C-Language when we write a c program then after writing we save the file
After this when we compile the File then our code is transferred in machine
language and an other file (called Object file) is created. This file is
extension “. OBJ “.
In the end when we want to execute our file first of all we make executable
Preprocessor Directive
Preprocessor Directive are the lines included in program with the character# which
processor directives are execute before compile actual program. with the help of
Preprocessor Directive we can inlcude the header files in our program or define
#include<filename>
#define
#undefine
For example :
#include<conio.h>
Formatted Input/Output
printf() and scanf() functions are inbuilt library functions in C programming language.
'Printf and Scanf function are used for formatted INPUT and OUTPUT. We have to
include “stdio.h” file as shown in below C program to make use of these printf() and
scanf() in C language.
Printf Function:
Printf allows formatted out put of data. In C programming language, printf() function
is used to print the “character, string, float, integer, octal and hexadecimal values”
control string.
Syntax:
Scanf Function: -
language, scanf() function is used to read character, string, numeric data from
keyboard .
2. Control string followed by &variable name into which the typed response will
be placed.
Syntax:
gets( ) function:
The gets function is used to read a single line (until new line is encountered). When
all input is finished (when enter key is pressed) a NULL character is append at the
Syntax:
puts () Function:
This function is used to print the string values on screen. When output of string is
Syntax:
getch () Function:
Getch stand for "Get character ". This function is used to get the single character
From the user during the execution of program. When we input the character then its
not display on the screen and control is transfer to next statement with out pressing
enter key.
Syntax:
getch () Function:
getche () Function:
This function also gets the character form the user at time of execution. When we
use getch then entered character not display on the screen but with getch character
Syntax:
getche () Function:
For example
X= getche();
When user enter the character then this character store in x (where x is a character
variable).
Format specifiers
Format specifiers are the sequence passed as the formatting string argument in
These are the special character that represent the type of out put and in put of
%d Integer
%f Float
%e Exponent
%g General
%c Character
%s Siring
%u Unsigned
%1 Long
%o Octal
%x Hexa
Transfer OF Control
Control Structure:
statement to other statement in that order in which these statement are written. But
some time we change this control according to our own need. For this purpose we
use transfer of control statements. Two types of transfer of control are used in C-
Language:
In this type of control a condition is given. If the condition is true than control is
transfer to specified statement. For this purpose we use Decision making statement
IF Statement
statement we give a condition after using “ IF “ key word. If the condition is “True “
and if the condition is "False” then nothing will be do and control is transfer to next
“ We say that if statement allows you to execute specific parts of a program if certain
If structure contain three main parts. The first is the keyword “ if “. The second is
of code (which is written in parentheses) that you want to run if the condition met to
given condition.
Syntax:
statement 1;
statement 2;
}
IF-Else Statement
statement we use two Keyword “ IF “ and “ ELSE “ we give a condition after using “
“ We say that if statement allows you to execute specific parts of a program if certain
Syntax:
If (Condition)
statement 1;
statement 2;
{
else
statement 1;
statement 2;
Note: - If the statement block is only one statement, the braces are not necessary.
Example: - Scan a number from user and display message that number that enter
is
+ve or -ve.
main()
int n;
scanf(“%d” , &n ) ;
if(n>=0)
printf("number is +ve") ;
else
getch( );
}
In above example user enter a number. This number is stored in N (variable) then
condition is checked that number is greater then zero is less zero. If the number is
grater then zero its means that condition is true then message appear that "Number
is + ve " and if condition is false then message appear that "number is -ve".
NESTED IF
if statement.
it is used when we have multiple conditions to check and when any if condition
Syntax:
If (condition expression)
Block of statements
Else
In simple word when we have multiple choices or multiple conditions then we use
nested if-structure. For this purpose we put an other if statement in the body of first if
statement.
Example
main( )
int n ;
scanf (“ %d ” , &n ) ;
if(n== 1)
else
if(n==2)
else
if(n==3)
else
getch( );
in above example we see that if we enter 1(one) form keyboard then message
appear that "You enter One" other wise condition is again tested end the result is
prepared .
This is another form of the multi way decision. It is well structured, but can only be
Only one variable is tested, all branches must depend on the value of that variable.
A final, catch all, default branch may optionally be used to trap all unspecified cases.
In this example user enter a character and this program decides whether you enter
min( )
Char x ;
Break ;
Break ;
break;
default :
getch( ) ;
Each interesting case is listed with a corresponding action. The break statement
prevents any further statements from being executed by leaving the switch. Since
case 3 and case 4 have no following break, they continue on allowing the same
Loops. In simple word when we do some work again and again for specified period
For example if we want to print message "hello C" 100 times then there are two
First we use printf statement 100 time to print this message on the screen.
Second we write single statement in the body of the loop which print this message
100 time.
So we observed that second one method is simple and easy and less time
consuming.
In C language we have choice of three types of loop, for , while and do while .
Each time the body of the loop is executed is called iteration. When the number of
repetition (Iterations) is well known before the processing than we use count control
then we use event control loop. Event control loop repeated until some thing
If you are making a angle food cake and the recipe reads “Beat the Mixture 300
strokes” its means you are executing count control loop. And if recipe reads “ Beat
the Mixture until the Color of Mixture change in brown color “ its means you are
I am sure you well under stand these two structures. Now we discussed Three Loop
For loop
While Loop
Do While Loop
FOR LOOP
For loop is Count Control loop. The for loop works well, where the number of
iterations of the loop is known before the loop is entered. The head of the loop
The initial value: - This is usually the initialization of the loop variable and its initial
Condition: -The second part is a test; the loop is terminated when this returns false.
Step: - The third is a statement to be run every time the loop body is completed. This
statement 1;
statement 2;
statement 3;
Note: - If the statement block is only one statement, the braces are not necessary.
Example:
main( )
int i ;
printf( “ %d” , i) ;
getch();
This Program print 1 to 100 digit on screen so we see that only one statement
executed and 1 to 100 number print on the screen because of header of this
statement is for loop which repeatedly execute the statement below which print the
number.
While Loop: -
The while loop keeps repeating an action until an associated test returns false. This
is useful where the programmer does not know in advance how many times the loop
will be traversed.
The while construct consists of a block of code and a condition. The condition is
evaluated, and if the condition is true, the code within the block is executed. This
repeats until the condition becomes false. Because while loops check the condition
before the block is executed, the control structure is often also known as a pre-test
loop.
Syntax:
While (condition)
statement 1 ;
statement 2 ;
statement 3 ;
Note: - If the statement block is only one statement, the braces are not necessary.
Example:
main()
{
int x = 1 ;
x++;
getch( );
This program also displays 1 to 100 digits on screen. But there is no counter as in for
loop. In this while loop x++ increment in the value of x one time and transfer the
control to while loop and check if x<=100 then again execute the printf statement and
then increase the x. this loop is terminated when x increases the value of 100.
Do While Loop:
The do while construct consists of a block of code and a condition. First, the code
within the block is executed, and then the condition is evaluated. If the condition is
true the code within the block is executed again. This repeats until the condition
becomes false. Because do while loops check the condition after the block is
executed, the control structure is often also known as a post-test loop. Contrast with
the while loop, which tests the condition before the code within the block is executed.
The do while loops is similar to while loop, but the test occurs after the loop body is
executed. This ensures that the loop body is run at least once.
Syntax: -
Do
statement 1 ;
statement 2 ;
statement 3 ;
Note: - If the statement block is only one statement, the braces are not necessary.
Example: -
Main()
int x = 11 ;
do
getch( );
}
We see as the value of x is greater then 10 in the start but printf statement executed
one time and then condition is test which identify that x > 10 so return False and loop
Continue Statement:
In some programming situation we want to take the control to the beginning of the
loop by passing the statement inside the loop. Which have not yet been executed.
then control transfer to the beginning of the loop with out executing the statements
For example if we want to print all the number form 1 to 100 but those number are
not printed which are divisible by two. The C program for this purpose is as follow.
main()
int n ;
if(n%2==0)
continue ;
}
getch( ) ;
Break Statement:
When we want to jump out form the loop with out waiting to get back to test condition
main ( )
int i ;
clrscr( );
if (i==50 )
break ;
printf(“ %d” , I) ;
getch() ;
}
We see that in this program we use for loop to display the number 1 to 100 . but
using break statement before the printf statement stopped the loop when counter
Nested Loop:
The placing of one loop inside the body of another loop is called nesting. When you
"nest" two loops, the outer loop takes control of the number of complete repetitions
of the inner loop. While all types of loops may be nested, the most commonly nested
For example:
main ( )
int i , j ;
clrscr( ) ;
printf(“Hello c \n “);
getch( ) ;
In this above program inner loop is executed 3 times for every iteration of outer loop
so total iteration are 9. Its means that printf statement repeated 9 time and “ Hello C”
Array is collection of variable, which are same in nature and store in contagious
memory location. In simple word we say that array is collection of similar data
element, which are, store in continues memory location with a single name.
Second is we declare a single subscripted variable which store the marks of 100
Student.
Subscripted variable:
it is the variable, which represent the individual element of array. It is use to access
the index begins at zero and is always written inside square brackets.
shape of vector means in one row or one column. The elements of the array stored
Declaration of Array
statement.
Data type is any valid C data types like integer, character etc.
Values are optional we specify the value of each element of array at time of
declaration of array.
For example
int num[3]={2,5,7];
num[0]=2
num[1]=5
num[2]=7
Example of array
main()
{
int st[5] ;
clrscr( ) ;
printf( “ %d “, st[ i ] ) ;
getch ( ) ;
Above program gets the marks of five students and then after getting marks clear the
screen and then print list of all the marks that you entered.
When data are store in more then one row or more then one column then this type of
Dimensional array.
Data elements are store or access in two-dimensional array with the help of two-
subscripted variable.
Declaration of array:
Syntax:
For example
Programming Example:
main ( )
clrscr() ;
printf(" \n " );
getch( ) ;
This program gets the number for matrix and then print in special form of matrix.
Like that
String Processing
Character Array (String )
When characters store in array (in Consecutive memory location) then it is called
string.
within double quotation symbols is a string constant. In “ c “ it is required to do some
The last character of the character array is NULL character. when we enter a string
then each and every character take place in the array and when we press enter key
then a NULL character will place in the end of the string which tell that this is end of
the array.
For example:
Null Character play important role in string because this is only way which tell that
Then the string name is initializing to “ Toqeer “. This is perfectly valid but C offers a
The above string can be initialized char name[ ]=”Toqeer”; The characters of the
string are enclosed within a part of double quotes. The compiler takes care of storing
the ASCII codes of characters of the string in the memory and also stores the null
On the other hand when we print the string value then we use %s format specifier
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void main()
char name[10];
clrscr();
scanf("%s",&name);
cout<<name;
getch();
#include<iostream.h>
you can also use gets( ) and puts ( ) function for string processing
main()
char month[15];
gets (month);
getch( );
As we now that character array actually represents the string values. So when we
declare any string variable this variable already a one dimensional character array.
And when we want to store more then when string values we declare two-
When we declare
Char name[25][3];
Where first subscript value 25 means that every value in this character array have
maximum 25 character and 2nd subscript 3 tell that only three string values store in
this array.
For example :
char I , name[25][5];
clrscr( ) ;
for( i=0;i<=4;i++)
gets(name[ i ]);
for(i=0 ; i<=4 ; i++)
puts(name[ i ] );
getch( ) ;
In this example when we get name then we don't mention the first subscripted
Variable as we use gets (name [ i ] where [ i ] represent name [0], name [1], .name
[3], name[4] means that name at first location name, 2nd location name, 3rd location
name and it is re-usable i.e. it can be executed from as many different parts in a C
In simple word we suppose you have a task, which is always performed exactly in
the same way. Like monthly service of the motorbike. When you want it to be done,
you go to the service station and say "its time of service do it now". You don't need to
In the same way when we have some kind of work, which performs always in same
way like that factorial of the number then we only, tell the number a function return
the factorial.
“main()” function or for any where. A function can be called from within
another function.
A function is independent and it can perform its task without intervention from
1. Function declaration
2. Calling function
3. Function Definition
1) Function declaration: -
Function declaration is also called prototype. This is one line statement and always
written before the declaration of main( ) function. Its consist on name, type of the
Specify the type parameters, which are provided to function. If more then one
Where void means this function does not return any value and no values is passed
to this function.
Hare int means that this function returns integer value. And two integer values
2) Calling Function: -
We can call function any where form any function. For this purpose we use calling
statement.
Syntax:
èWhere variable name is optional if function return any value then we give variable
èArguments are those variables, which represent the values, which passing to
function.
3) Function Definition: -
Function Definition is actually the function, a task that is performed when we call this
main ( ) function. Function Definition is written any where after the main function.
For Example
In following program we pass a number to function that calculate the factorial and
appropriate places.
A function may be used later by many other programs this means that a c
programmer can use function written by others, instead of starting over from
scratch.
A function can be used to keep away from rewriting the same block of codes
Debugging is easier.
Testing is easier.
Recursion:
When a function call its self in its body then this process is called recursion and this
Pass By Value:
main ( )
int b = 10;
square (b);
//body of function
printf ( “ %d” , n * n ) ;
In this function, ‘n’ is a parameter and ‘b’ (which is the value to be passed) is the
argument. In this case the value of ‘b’ (the argument) is copied in ‘n’ (the parameter).
Hence the parameter is actually a copy of the argument. The function will operate
only on the copy and not on the original argument. This method is known as PASS
BY VALUE.
Call by Reference:
When we pass address to a function the parameters receiving the address should be
pointers. The process of calling a function by using pointers to pass the address of
the variable is known as call by reference. The function which is called by reference
main ( )
int n = 10;
square (&n);
As you can see the result will be that the value of a is 100. The idea is simple: the
argument passed is the address of the variable n. The parameter of ‘square’ function
is a pointer pointing to type integer. The address of n is assigned to this pointer. You
can analyze it as follows: &n is passed to int *x, therefore it is the same as:
Int * x = &n ;
This means that ‘x’ is a pointer to an integer and has the address of the variable n.
*x = (*x) * (*x) ;
* (star symbol ) when used before a pointer will give the value stored at that
particular address.
Type OF Function:
Library functions
User-defined functions
are not required to be written by user while the latter have to be developed by the
user at the time of writing a program. However the user defined function can become
These are also called built in function. When we use these types of functions then
often we include some headers files. Such that when we use sqrt ( ) function which
calculate the square root of the number then we include the math.h header file.
C program uses both built in function and function (which is also called user defined)
built in function means the declaration and the compiler already knows definition of a
function.
User defined function) means user is going to declare and define that function in the
(already exist), but User defined function are functions that created by the user.
For example:
# include <math.h>
Strlen ( ) Function: -
Description
Syntax :
Example:
printf("%d",strlen("Toqeer"));
Return 6
Strcpy ( ) Function: -
Description
The strcpy functions copy the source string to destination (including the terminating '\
0' character.)
Syntax:-
Example:
char name1[10];
char name2[10];
scanf("%s",name1);
strcpy(name2,name1);
Strncpy ( ) Function: -
Description
The strncpy functions copy the given number of character from source string to
destination.
Syntax:-
Strncpy(source string, String Variable, n[number of the character
to be copied)
Example:
int main()
char name1[10];
char name2[10];
scanf("%s",name1);
strncpy(name2,name1,2);
name2[2] = '\0'; /* Add the required NULL to terminate the copied string */
return 0;
Strcat ( ) Function: -
Description
Syntax:-
Strcat(S1 , s2 )
Example:
int main()
strcat(str1,str2);
puts(str1);
}
The Output is “This is learninghints.com”
Strncat ( ) Function: -
Description
Strcat function append the specify number of the character from on e string to other.
Example:
int main ( )
strcat(str1,str2);
puts(str1);
srrcmp ( ) Function: -
Description
strcmp compare two string if they match with each other its return zero (0). If s1 > s2
Syntax:
Strcmp(s1, s2)
Exapmle:
int main()
cout<<strcmp(str1,str2);
Numeric Function
ABS( ) Function:
This function return the absolute value of the given signed value.
Syntax:
Example:
Int n = -8
Sin( ) Function:
Syntax:
cos( ) Function:
cos ( ) function return the cos value of any given value.
Syntax:
This function returns the Tangent value of any given value. Min() Functien:-
min ( ) Function:
This function returns the minimum value from the given list.
Syntax:
For example:
cout<<min(1,2) ;
Return 1
max() function:
This function returns the maximum value from the given list.
Syntax:
For example:
cout<<min(1,2) ;
Return 1
pow() Function:
This function is used to calculate the power of the given value.
Syntax:
Row ( X , N)
For example:
#include<bits/stdc++.h>
cout<<pow(4,2);
Return 16
Sqrt ( ) Function:
Syntax:
Example:
#include<bits/stdc++.h>
cout<<sqrt(4);
rand function : -
rand will generate a random number between 0 and 'RAND_MAX' (at least 32767).
Syntax:
rand( ) ;
Example:
srand ( ) Function:
Srand will seed the random number generator to prevent random numbers from
being the same every time the program is executed and to allow more pseudo-
random number.
Example :
srand(time(0));
printf(" %d \n",rand());
hex( ) Function: -
Convert an integer number (of any size) to a hexadecimal string. The result is a valid
Python expression
Example:
int n = 5895;
round( ) Function: -
Return the floating point value x rounded to n digits after the decimal point. If n is
Syntax:
Round ( x [ , n ] )
int main()
float x = 13.87;
int result;
result = round(x);
cout << "round(" << x << ") = " << result << endl;
return 0;
Character Function
Isdiqit ( ) Function:
This function determine the nature of the given character, whether the given
character is digit or not. If the given character is digit then its return any +ve number
Syntax:
int main()
{
char c;
c='5';
return 0;
Issupper ( ) Function:
Syntax:
int main()
char ch='X';
if (isupper(ch))
else
return 0;
}
Isspace( ) Function:
This function is used to check if the arguement contains any whitespace characters.
‘’- “Space”
Syntax:
int main()
if (isspace(ch))
else
Output :
isalpha( ) Function:
This function determine, whether the given character is alphabet or not. If the given
Syntax:
int main()
char ch='a';
if (isalpha(ch))
else
return 0;
Structures in C
of different types together. A simple variable can store a single value. And an array
stores the more then one value of similar data item in consecutive memory locations.
But if we want to store the more then one dissimilar data element in array this is not
possible.
For example if we want to store the information about book, which contain name of
the book (String value), Price of The book (float value) and page of the book (integer
value). This is not possible in array. C provides us an other solution to solve this
Structure may be declared local to function in very start of the function. struct
keyword is used to define a structure. struct defines a new data type which is a
};
main ( )
struct book;
char name[50] ;
int page ;
int price ;
};
struct book b;
b.name=”Visual Basic”;
b.page=100;
b.price=150;
getch();
Structure Array
When we want to store the more then one element of structure data type then we
use structure array. For this purpose we use same method of declaration of structure
In simple structure we declare single object variable but in case array we declare
#include <iostream>
#include <conio.h>
#include <stdio.h>
struct Student
char name[50];
int page;
int price;
};
int main()
int i;
scanf("%s",b[i].name);
scanf("%d" , &b[i].price);
}
for(i=0; i<=2 ;i++)
return 0;
POINTERS
Pointer is a way of accessing a value, which is stored in memory with out referring to
the variable name directly. Pointer refers the address of the variable.
Pointer variable:
stored. Each memory cell in the computer has an address that can be used to
access that location so a pointer variable points to a memory location we can access
and change the contents of this memory location via the pointer.
For example:
int *K ;
Where K is pointer variable, which store the address of any other variable. When we
declare variable then three type of information about that variable take place.
Reserve space in memory to hold the integer.
For example:
Pointer declaration:
A pointer is a variable that contains the memory location of another variable. The
syntax is as shown below. You start by specifying the type of data stored in the
location identified by the pointer. The asterisk tells the compiler that you are creating
Example:
int * ptr ;
float *string ;
Address operator:
Once we declare a pointer variable we must point it to something we can do this by
assigning to the pointer the address of the variable you want to point as in the
following example:
Ptr = & n ;
This places the address where n is stores into the variable ptr. If n is stored in
memory 10101 address then the variable ptr has the value 10101.
Printf(" % d " , n ) ;
But if we give instruction in such way that print the value at address 10101 then
For example
Printf ( “ % u” , ptr)