using codeblocks
------------------------------------------------------------------------------------------
//program to reverse a string using pointer//comment of program
#include <stdio.h> //header file
int main() //main function
{
char name[40]="ramesh Shrestha"; //assignment of string
char *p; //pointer declaration
p=name+15; //p=name takes address location 0 to pointer.
// assigning total address as in given string; it becomes 15 starting from 0
while(--p>=name) //the value of 'p' decreases from location 15 until it reaches 0.
{
putchar(*p); //prints the value stored in particular location
}
return 0;
}
------------------------------------------------------------------------------------------
//program to reverse a string using pointer//comment of program
#include <stdio.h> //header file
int main() //main function
{
char name[40]="ramesh Shrestha"; //assignment of string
char *p; //pointer declaration
p=name+15; //p=name takes address location 0 to pointer.
while(--p>=name) //the value of 'p' decreases from location 15 until it reaches 0.
{
putchar(*p); //prints the value stored in particular location
}
return 0;
}
----------------------------------------------------------------------------------------------------
using turboc++
--------------------------------------------------------------------------------------------
//program to reverse a string using pointer//comment of program
#include <stdio.h> //header file
#include<conio.h>
int main() //main function
{
char name[40]="ramesh Shrestha"; //assignment of string
char *p; //pointer declaration
p=name+15; //p=name takes address location 0 to pointer.
// assigning total address as in given string; it becomes 15 starting from 0
while(--p>=name) //the value of 'p' decreases from location 15 until it reaches 0.
{
putchar(*p); //prints the value stored in particular location
}
getch();
return 0;
}
No comments:
Post a Comment