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
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...
-
Character constant: • Character constant is a single alphabet,a single digit or a single special symbol. • Rules for constructing char...
-
1] strcmp() function : ▪️ This function compares two strings to find out whetherthey are same ordifferent. ▪️ If two strings ar...
-
C-language has an unusual operator, useful for making two=way deciaions. The operator is a combination ( ? ) and ( : ) and this operand. Th...
