Wednesday, September 30, 2020
Tuesday, September 29, 2020
Pointer of string with example
Pointer of string:
▫️ As we can have the pointer togeneral array, we can also have a pointer to string .
When we storethe string address of the string to the pointer variable, this pointer variable is called as pointer to string.
char string variable [size],*ptr;
Ex ptr = &string1[0];
Example :
#include<stdio.h>
#include<conio.h>
# include<string.h>
main( )
{
char str[80],*ptr;
int k,length,count=0, M=0, R=0, U=0, G=0, N=0, A=0, Y=0, N=0, I=0;
printf("Enter a line of text\n");
gets(str);
length=strlen(str);
ptr=str;
for(k=0;k<length;k++)
{
if( (*ptr=='m') || (*ptr=='M') )
{ M++; count++;}
if( (*ptr=='r') || (*ptr=='R') )
{ R++; count++;}
if( (*ptr=='u') || (*ptr=='U') )
{ U++; count++;}
if( (*ptr=='g') || (*ptr=='G') )
{ G++; count++;}
if( (*ptr=='a') || (*ptr=='A') )
{ A++; count++;}
if( (*ptr=='n') || (*ptr=='N') )
{ N++; count++;}
if( (*ptr=='a') || (*ptr=='A') )
{ A++; count++;}
if( (*ptr=='y') || (*ptr=='Y') )
{ Y++; count++;}
if( (*ptr=='a') || (*ptr=='A') )
{ A++; count++;}
if( (*ptr=='n') || (*ptr=='N') )
{ N++; count++;}
if( (*ptr=='i') || (*ptr=='I') )
{ I++; count++;}
Ptr++;
}
printf("Name of character present in screen = %d \n",count);
printf( "M = %d \n",Y);
printf( "R = %d \n",R);
printf( "U = %d \n",U);
printf( "G = %d \n",G);
printf( "A = %d \n", A);
printf( "N = %d \n",N);
printf( "A = %d \n",A);
printf( "Y = %d \n",Y);
printf( "A = %d \n",A);
printf( "N = %d \n",N);
printf( "] = %d \n",]);
}
Output:
Enter the line text
Mrunali is best in all student
Name of character present in screen = 12
M = 1
R = 1
U = 2
G = 0
A = 2
N = 3
Y = 0
I = 3
Monday, September 28, 2020
What is control structure ? with flow chart
Sunday, September 27, 2020
1] Local variable 2] Globle variable 3] Calling function 4]Called function 5] Actual argument f] Formal argument.
1] Local variable:
▪️ A variable that is declared within the function , it is called local variable.
▪️ The scope of local variable can be accessible only from within the function in which it is declared.
▪️ Local variable can accessible only from within the function in which it is declared.
2] Global variable:
▪️ A variable that is declared outside of all the functions, it is called global variable.
▪️ The scope of variable is whole the program. In other words, it can be used in any function of the program.
▪️ Global variable can be accessible from all the function of the program.
3] calling function:
▪️ A function that has a statement to call another function, is called calling function.
▪️ Control of program is transferred to the call function,after executing all it's statements, the program control is sent back to the calling function.
4] called function:
▪️ Function that has been called from another function is known as called function.
▪️ program control is transferred from the calling function to the called function, after executing all it's statements, the control is sent back to the calling function.
5] Actual argument:
▪️ When we pass argument at the time of calling of function, these arguments are known as actual arguments.
▪️ Values of actual argument at the copied in to formal arguments.
▪️ We can also transfer the address of actual arguments to the format arguments,if the formal arguments are pointer variable.
6] Formal argument:
▪️ The arguments that will collect the values/addresses of actual arguments are called formal arguments.
▪️ Formal arguments are defined within the function defination, in function header.
▪️ There should be match the actual and formal arguments in number, type,and sequence.
▪️ consider the following example:
#include<stdio.h>
void display(int);
int p;
void main( )
{
int a = 15;
p = 10;
printf("Global variable = %d",p);
printf("Local variable = %d",a);
p = 20;
display(a);
}
void display (int x)
{
int y = 100;
printf("Global variable=%d,p);
printf("Formal argument of display=%d",x)
printf(Local variable of display=%d",y);
}
Output:
Global variable=10
Local variable of main=15
Global variable=20
Formal argument of display=15
Local variable of display=100
Saturday, September 26, 2020
Explain string function with example.1]strcmp(), 2] strupr(), 3]strlwr(), 4]strrev(), 5]strstr(), 6]strset().
▪️ This function compares two strings to find out whetherthey are same ordifferent.
▪️ If two strings are found identitcal, this function returns zero "0", otherwise returns a numeric difference between ASCII valueof non matching characters.
▪️ The general form of strcmp() is
I=strcmp(str1,str2);
Example:
#include<stdio.h>
#include<string.h>
void main()
{
int i ;
char s1[15]="Mrug garud",s2[15]="Mrug kolhekar";
i = strcmp(s1, s2);
if(i == 0)
{
printf(" two strings are same");
}
else
{
printf( " two strings are different");
}
}
2] strupr() function:
▪️ Thisfunction converts the caracters of string variable to upper case.
▪️ The general format of strupr() is
Strupr(string);
Example:
#include<stdio.h>
#include<string.h>
void main()
{
char name [15]="akash";
strupr(name);
printf("Enter your good name=%s",name);
}
▪️ Output:
Enter you good name= AKASH
Friday, September 25, 2020
Explain string functions with example.
1] gets() :
▪️ The function gets() receives the string from an input device.
▪️ At the end string, the function gets() appends a null character.
▪️ The gets() function takes the following from:
gets(str);
▪️ Example:
void main()
{
char str[80];
printf( "Enter your name ");
gets(str);
printf(" Welcome ! %s",str);
}
Output:
Enter your name
Sky Eagle
Welcome ! Sky Eagle
2] strlen() function:
▪️ This function returns length of string passing to it.
3 Hence it returns an integer value that must be collected within a variable .
4 It takes the following gereral format.
L = strlen ( str );
Example:
#include<stdio.h>
#include<string.h>
Void main()
{
char str[ ]="Hello friends";
int length;
length=strlen(str);
Printf("length of string=%d",length);
}
Output:
length of string = 6
Wednesday, September 23, 2020
What is a string ? Explain string declaration and initialization with suitable example.
* String :
1] "String is one dimensional array of type char".
2] Every string is "C" terminates with null character [\o].
3] The string constant is a set of characters enclosed in double quotation.
Example :
Declaration Of String Variable :
1] The character array may be initialized at the time of declaration also.
2] It can be initialized into two two ways.
First way : char city [10]={'P','U','S','A','D'};
Second : char city [10]="PUSAD" ;
3] If an array is initialized where it is declared, mentioning the sizeis optional as in the following example. At this time, the size of array will be determined automatically, based on the number of element initialized.
First way : char name [ ]=" Sky " ;
Second way : char city [ ]={'H' , 'Y' , 'D'};
void main()
{
char name[80];
printf("Enter your name");
scanf("%s", name);
printf("You have entered=%s",name);
}
Output:
Enter your name
Eagle
Your have entered=Eagle
* Representation of string variable(char type array) in a memory:
Array elements are always stored in a contagious memory location.Consider the following example.
char A [5]=" Sky " ;
It can be represented in a memory as.
Element= A[0] A[1] A[2] A[3] A[4]
Value = S K Y '\0'
Address= 9770 9371 9372 9373 9374
Saturday, September 19, 2020
Explain for statement flow chart with example
* for statement :
The for loop is entry controlled loop that provides more concise structure.
The general form of for loop is
for(initialization;test-condition;increment/decrement)
{
body of loop
}
* Flow chart :
The execution of the for loop is as follow
▪️ initialization of the control variable is done first,using assignment statement such a i = 1.
the variable[ i ] is known as loop-control variable.
▪️ the value of the variable is tested using the test-condition.
the test condition is a relational expression such as i<=10 that determines when the loop will exit.
If condition is a true,the body of the loop is executed; otherwise loop is terminnated and the execution continues with the statement that immediatly follows the loop.
▪️ when the body of the loop is executed, the control is transferred back to the for statement after evaluating last statement in the loop.
Now the control variable is incremented ordecremented using an assignment statement such as i=i+1 or i=i-1 etc and the new value is again tested to see wheather it satisfies the loop condition.
This process continues till test condition becomes false.
consider the following example :
for(x=1; x<=10, x++)
{
printf("%d",10*x);
}
In above example table of 10 will be displayed.
Friday, September 18, 2020
else-if ladder in c-programming
else-if ladder :
There is another way of putting if's together when multipath decisions are involved.
A multipath decision is a chain of if's in which the statement associated with each else is an if.
It takes the following general form.
if( condition 1 )
statement 1 ;
else if ( condition 2 )
statement 2 ;
else if ( condition 3 )
statement 3 ;
else if ( condition n )
statement n ;
else
default statement ;
statement-x
This construct is known as else if ladder.
The conditions are evaluated from the top to bottom.
As soon as a true condition is found , the statement associated with it is executed and control is transferred to the statement-x.
When all the conditions are false , then the final else containning the default statement is executed.
Following figure shows the logic of execution.
Concider the following example
if ( n==1 )
printf ("Monday");
else if ( n==2 )
printf ("Tuesday");
else if ( n==3 )
printf ("Wednesday");
else if ( n==4 )
printf("Thursday");
else if ( n==5 )
printf("Friday");
else if ( n==6 )
printf("Saturday");
else if ( n==7 )
printf("sunday");
In above example accordig to the value of n day name will be displayed.
Thursday, September 17, 2020
jump in loop (jumping out of a loop )
Jumps in loop :
• Loops perform a set of oprations repetedly until the control variable fails to satisfy the condition sometimes, when executing a loop it becomes desirable to skip a part of a loop or to leave the loop as soon as certain condition occurs.
• C-permits a jump from one statement to another within a loop as well as jump out of a loop.
Jumping out of a loop (break statement)
• An early exit from a loop can be accomplished by using break statement.
• When a break statement
Wednesday, September 16, 2020
Switch statement exapression with example
Switch statement :
We know that when one of the many alternative are to be selected, we can use ladder if statement to control the selection.
However the complexity of such a program increases when the no.of alternative increases.
The program become difficult to read and follow.
At time, it may confuse even the person who designed it.
Therefore c have a built-in multiway decision statement known as switch.
The switch statement test the value of a given variable against a list of case values and when a match is found, a block of statement associated with that case is executed.
The general format of switch statement is.
Switch (expression)
{
case value - 1 :
block - 1
break ;
case value - 2 :
block - 2
break ;
. . . . .
. . . . .
default :
default - block
}
statement - x ;
The expression is an integer expression or characters.
Value 1, value 2, value 3. . .are constants or constant the expressions and are known as case labels .
Each of should be unique within a switch statement.
Block-1, block-2, block-3,.....are statement lists that contain zero or more statements.
Case labels end with a colon ( : ) .
When the switch is executed, the value of the expression is compared with the values value-1 , value-2 , value-3 ,.....
If a case is found whose value matches with the value of expression, then the block of statements that follows the case is executed.
The break statement at the end of each block causes an exit from the switch.
The default is an optional case, when present it will be executed if the value of the expression does not match with any of the case value.
If not present , no action takes place if all matches fail and the control goes to the statement after the switch statement .
The selection process is illustratedin the following flowchart.
Consider the following example
switch( digit )
{
case 1:
printf("one ");
break;
case 2:
printf( two );
break;
case 3:
printf( three );
break;
case 4:
printf( four );
break;
case 5:
printf( five );
break;
}
In above example the value of variable digit will be displayed in words.
Tuesday, September 15, 2020
Nested if-else statement
Nested if-else statement :
When a series of decisions are involved we may have to use more than if statement in nested form as follows :
if ( test -condition-1)
{
if ( test-cndition-2)
{
statement - 1
}
else
{
statement - 2
}
}
else
{
statement - 3
}
statement - x
The logic of execution is if the condition - 1 is false then the statement - 3 is executed otherwise it continues to perform the condition - 2. if the condition - 2 is true, the statement - 1 is executed otherwise statement statement - 2 is executed. it is shown in following flowchart
Consider the following example
if ( a>b)
{
if (a>c)
{
printf("%d",a);
{
else
printf("%d",c);
}
}
else
{
if(b>c)
{
printf("%d",b);
}
else
{
printf("%d,c");
}
}
In above exemple, greater number from a, b and c will be displayed.
Sunday, September 13, 2020
Conditional operator Statement(? :)
Saturday, September 12, 2020
Array, one- dimensional array, two-diamensional array, multi-diamensional array.declaration and initializalion with example.
ARRAY :
1] Array is the collective name given to a group of similar quantity or variables that are stored in consecutive memory locations.
2] Each member/element of a group is referred by its position in the group.array is also known as subscripted value or indexed variable.
3] There are different types of array such as one, two and multi dimensional arrays.
One Diamensional Array :
An array declared with single subscript is called one dimensional array follows:
Declaration Data_type Array_name[size];
Ex: int employee[10];
Initialization: The general form of initialization of one dimensional arrays is:
Data_type Array_name[size]={list of values};
Ex: int employee[5] ={88,05,93,70};
Friday, September 11, 2020
Write a program to generate following pattern.
1] * 3] * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *
Solution 1:
#include<stdio.h>
main()
{
int i , j ;
for(i=1 ; i <=5 ; j++)
{ for(j=1 ; j<=i ; j++)
{ printf(" * "); }
Printf("\n");
}
}
Output :
*
* *
* * *
* * * *
* * * * *
Thursday, September 10, 2020
Explain with example octal,hexadecimal,integer and real number
Integer constant :
Integer constant is nothing but a whole number
Integer constants are positive unless they are preceded by a minus sign (-).
3] An " integer constant " is decimal number. We can provide decimal value to the variable directly as follows:
Declaration int variable=value (decimal);
Example int A = 127 , B = -100;
Tuesday, September 8, 2020
What is real/floating point constant? Syntax and rules for constructing
Real constants:
Real constant are often called floating point constant.
The real constant could be written in two forms, fraction form & exponential from.
Real for constructing real constant in exponential form are as:
1] A real constant must have at least one digit.
2] It must havedigital point.
3] The mentissa part and the exponential should be separated by letter " e " or E .
3] It must could be +ve or -ve default sign is +ve.
4] No commas or blank space are allowed within real constant.
5] Ex: +325.34, 10.0, -326.4, -48.5697
The exponential form of representation of real real constant is usually used when the value of the constant is either too small or too large.
In exponential forma real constant is reprented in to two parts.
The part appearing before " e " is called mantissa, where as the part following " e " is called exponent.
rules for constructing real constant.
1) The mentissa part and the exponential part should be separated by letter " e " or "E".
2) The mentissa part may have +ve or -ve sign,default sign is +ve.
3) Exponent must have at least one digit, which must be +ve or -ve , default sign is +ve.
4) Range of real constant in exponentiation is -3.4e38 to 3.4e38
5) Ex: 3.2e-5, 4.1e8, -0.2E+3, -3.2e-5.
Types of madifiers used in c-program with examples
* Data type modifier:
We have so far learned about the fundamrntal data type, the data type madifier is used to limit the behavior of basic data type.
The following are the different data type modifier.
Sined:
By default all data types are declared as signed, means that the variable of data type is capable of storing negative value also.
Unsigned:
To modofy a data type's behavior so that it can only store positive values, we required to use the data type unsigned.
For example: if we want to declare a variable age,we know that an can not be represented by negative values and hence,we can modify the default behavior of the int data type as follow:
Unsigned int age;
Long:
Many times in our programs we want to store values beyond the storage capacity of the basic data types.
In such cases we used the data type modifier long.
This doubles the storage capacity of the data type being used.
Ex: long int november will make the storage capacity of variable november are 4 bytes.
The exeption to this is long double, which modifier the size of the double data type to 10 bytes.
Please note that in some compilers this has no effect.
Short:
The short data type modifier reduces the size of the data type to half.
If we want to declara variable age we can declare age as follow:
Short int age;
unsigned short int age;
Monday, September 7, 2020
Stricture of c program.
* Structure of c program:
• C program can be viewed as group of building blocks called function.
• A c-program may contain one or more sections as shown below.
Variables in C. declaration and initiallization
* Identifiers:
1] Identifiers are used to identify variables, symbolic constants, functions, arrays etc.
2] Identifier names must be a sequence of letters and digits, and must begin with a letter.
3] These are user defined names.
4] Ex : sub1, sub2, total, roll_no, per[30], factorial();
Saturday, September 5, 2020
goto statement in c programming
goto statement :
• The function of goto statement is to transfer the programs control unconditionally, where you want.
• It requires label to identify the place where to control will be transferred.
• It can be used, anywhere in the program.
• It is not associted with any loop.
• "goto" is a keyword.
• It is unconditional jump instruction.
• Example:
{
if(i<=10)
{ break;}
printf("%d",i);
i=i+1;
}
if statement in c-programming
If statement :
• It is two way decision statement .
• The condition can be implemented by using relational expression.
• The condition is evaluated in the form of true or false.
• An "else" statement can also be used with "if" statement.
• No keyword that break the "if" block.
• syntax:
if(condition)
{
Block of "if" ;
}
Break statement in c-programming
Break statement:
• The break statement is used to pass the control out of the loop, by breaking the loop.
• It is used only with loops and "switch...case" statements.
• It always transfers the control to the next statement that follows it.
• Break is usually used with condition.
• The break statement is always associated with loops and switch case statements.
• "break" is a keyword.
• Example
While(condition)
{ if(i<=10)
{break;}
printf("%d",i);
i=i+1;
}
Friday, September 4, 2020
While & do..while statements
While statement:
• "while" test the condition before execution of the body of loop, therefore "while" is a entry controlled loop(also cknown as "top tested loop")
• The block of "while" may not be executed at all if the condition is not satisfied at the beginning.
• Syntax: of "while"
While(test condition)
{
Body of while;
}
• No semicolon is used after the condition.
• Example:
while(i<=10)
{
Printf("%d",i);
i=i+1;
}
Character Constants
Character constant:
• Character constant is a single alphabet,a single digit or a single special symbol.
• Rules for constructing character constant are as follows:
1] A character constant is a single alphabet, a single digit or a single special symbole, enclosed within a single inverted comma.
2] Both inverted commas should point to the left.
3] The maximum length for character constant can be 1 character.
Identifiers and keywords
Identifiers:
1] Identifires refer to the names of variables, funtions,symbolic constants and arrays.
2] Upper & lover cases are permitted, although lowercase letters are commonly used.
3] There is no limit on number of identifiers defined by user.
4] roll_no,Average,height,counter_1 etc.
Thursday, September 3, 2020
What is pointer variable
Pointer :
1] "A pointer is variable that holds address of another variable.
2] " * " symbol is used to declared the pointer variable".
3] Every pointer variable is associated with the variable,which is pointer by it.
4] syntax:
data_type * variable_name;
Int * ptr;
5] The above declaration shows a pointer variable ptr, which will hold the address of an "int"
What is dynamic arrays
Dynamic Arrays:
We created arrays at compile time . array created at compile time by specifying size in the source code has a fixed size and can not be modified at run time.
The process of allocating memory at compile time is known as static memory allocation and the arrays that receive static memory allocation are called static arrays.
This approach works fine as long as we know exactly what our data requirement are.
Consider are situation where we want to use an array that can vary greatly in size.
We must guess what will be the largest size even needed and create the array accordingly.
A difficult task in fact! Modern languages like c do not have this limitation.
In c it is possible to allocate memmory to arrays at run time.
This featureis known as dynamic memory allocation and the arrays created at run time are called dynamic arrays.
This effectively postpone the array definition to run time.
Dynamic arrays are created using what are known as pointer variable and memory management functions molloc, and calloc realloc.
These functions are included in the header file <stdlib.h>.
The concept of dynamic arrays is used in creating and manipulating data structures such as linked lists,stacks and queues.
gets() and puts() function
gets() :
• The function gets() receives the string from the standard input divice.
• It accepts string variable name as parameter,and fills the string variable with characters that are input from the keybord,till a newline character is encountered.
• At the end, the function gets() appends a null terminator.
• Syntax:
gets(str);
declaration: int gets(char*string pointer)
Keywords In C -Programming
Keywords:
• Auto • doubl •int • struct
• Break • else • long • switch
• Case • enum • register •typedef
• Char •extern • return •union
•Const • float •short • unsingned
•Continue •for • signed •void
•Default •goto • sizeof • volatile
•Do • if • static •while
Advantages and Disadvantages c-pogramming
Introduction Of C Programming And History Of C Languaghe
* Introduction of c programming:
1. C is a programming language developed at AT&T's Bell laborratories of USA in 1972.
2. C was designed and written by a man named Dennis Ritchie.
3. It is structured,high level,machine independent procedure oriented language.
* History of c programming:
1. Root of all modern language ALGOL,a block structured language,introduced in early 1960's.
2. In 1967,Martin Ritchards developed a language called BCPL(Besic combined programming language) primarily for writing system software.
3. In 1970, Ken Thompson created a language using many features of BCPL and called B. It was used to create early versions of UNIX operating system.
4. C was evolved from ALGOL,BCPL and B by Dennis Ritchie at the Bell and laboratories in 1972.the c language was become more popular after publishing the book "The c programming language"by Brian Kerningham and Dennis Ritchie in 1978.
5. In 1983,American National Standards Institude (ANSI) appointed a technical committee to define a standard for c.The committee approved version of c (ANSIC) in 1989.It was also approved by the International Standareds Organization (ISO) in 1990.This version is also referred as c89.
6. C++ added several new features to c to make it now only a true object-oriented language but also a moreversatile language.during the same period,sun microsystem of USA created a new language java modeled on and c++.
7. The standardization committee of c felt that a few features of c++/java,if added to c,would enhance the usefulness of the language.The resultant c was c99,in 1999.
Object Paradigm Oriented Programming in C++ / object oriented programming / History of C++/ paradiagram in c++/C devolop, Operating System, Unix operating system, Assembly language, popular in world, Programming language.
Object Paradigm Oriented Programming Two programmers, Brian Kernighan and Dennis Ritchie developed a new language called C, in 1972. C l...
-
Decion control statements: When dealing with section statements,there are generally three versions: 1 one-way 2 two way 3 three way One way...
-
if-else-if Ladder: A common programming construct is the if-else-if ladder, sometimes called the it- else-if staircase becaus...
-
Computer Graphics : ▪️ Computer graphics are graphics created using computer and, more generally, the repetation and manipulat...
by Michael Elkan