C program to reverse string using pointers


















Java Tutorial. The Set Interface in Java. Please enter your comment! Please enter your name here. You have entered an incorrect email address! Popular Categories. What is Machine Learning? A pointer is a variable whose value is the address of another variable, i. Like any variable or constant, you must declare a pointer before using it to store any variable address. However, in this statement the asterisk is being used to designate a variable as a pointer. Below is the source code for Program to reverse string using pointers and function which is successfully compiled and run on Windows System to produce desired output as shown below :.

Above is the source code for C Program to reverse string using pointers and function which is successfully compiled and run on Windows System.

In the second iteration, the value of p1 is 16 but the value of str is the same because we are not incrementing or decrementing the value of str. Again the condition in the while loop is true. In this iteration, blank space is read. Blank space is also a character. The output will look like the same as the above diagram only the values of p1 and p2 will be changed i. This is the last iteration because the value of p1 has become 10 which is equal to the value of the variable str.

In the next iteration, the value of p1 will become 9 and the condition in the while loop will become false and the loop will be terminated. In this way, we have written a program in c to reverse a string using a pointer. I hope you have understood this program.

I have also made a video on this topic in the Hindi language. Save my name, email, and website in this browser for the next time I comment. Introduction In this post, I am going to write a program to reverse a string in c using pointer. Now, let us see the actual program. Two normal variables and two pointer variables. Variable declaration with output In the above image, I am assuming memory locations for these variables str1, str2, p1 and p2. Also Read : C Program to Remove Zeros from a number This string will be stored in the variable str1 using the gets function.

Initialization of Pointer Variables Initialization of Pointer Variables Now, we need to initialize the pointer variables p1 and p2. Also Read: The while loop in C Programming while loop This is important part of the program to reverse a string in c.

First Iteration program to reverse a string in c using pointer — first iteration As we know that the value of p1 is 17 and str is also Here, the condition is true and following steps will be executed. G will be stored at the address which is stored in the pointer variable p2 i.

You can see the above diagram.



0コメント

  • 1000 / 1000