using codeblocks
--------------------------------------------------------------------------------------------
//program to reverse a string using pointer//comment of program
#include <stdio.h> //header file
#include<string.h>
int main() //main function
{
char name[40]; //character declaration
char *p; //pointer declaration.
int length;
puts("enter string\n"); //display of message
gets(name); // gets data/string
length=strlen(name); //stores length os string
p=name+length;
// assigning total address as in given string; it becomes total taken from variable length starting from //0.
//p=name takes address location 0 to pointer.
while(p>=name) //the value of 'p' decreases from total location until it reaches 0.
{
putchar(*p); //prints the value stored in particular location
p--; //decreases the value
}
return 0;
}
--------------------------------------------------------------------------------------------
//program to reverse a string using pointer//comment of program
#include <stdio.h> //header file
#include<string.h>
int main() //main function
{
char name[40]; //character declaration
char *p; //pointer declaration.
int length;
puts("enter string\n"); //display of message
gets(name); // gets data/string
length=strlen(name); //stores length os string
p=name+length;
// assigning total address as in given string; it becomes total taken from variable length starting from //0.
//p=name takes address location 0 to pointer.
while(p>=name) //the value of 'p' decreases from total location until it reaches 0.
{
putchar(*p); //prints the value stored in particular location
p--; //decreases the value
}
return 0;
}
----------------------------------------------------------------------------------------------
using turbo c++
----------------------------------------------------------------------------------------------
//program to reverse a string using pointer//comment of program
#include <stdio.h> //header file
#include<string.h>
#include<conio.h>
int main() //main function
{
char name[40]; //character declaration
char *p; //pointer declaration.
int length;
puts("enter string\n"); //display of message
gets(name); // gets data/string
length=strlen(name); //stores length os string
p=name+length;
// assigning total address as in given string; it becomes total taken from variable length starting from //0.
//p=name takes address location 0 to pointer.
while(p>=name) //the value of 'p' decreases from total location until it reaches 0.
{
putchar(*p); //prints the value stored in particular location
p--; //decreases the value
}
getch();
return 0;
}
#include <stdio.h> //header file
#include<string.h>
#include<conio.h>
int main() //main function
{
char name[40]; //character declaration
char *p; //pointer declaration.
int length;
puts("enter string\n"); //display of message
gets(name); // gets data/string
length=strlen(name); //stores length os string
p=name+length;
// assigning total address as in given string; it becomes total taken from variable length starting from //0.
//p=name takes address location 0 to pointer.
while(p>=name) //the value of 'p' decreases from total location until it reaches 0.
{
putchar(*p); //prints the value stored in particular location
p--; //decreases the value
}
getch();
return 0;
}
No comments:
Post a Comment