OUTPUT (after running):
Enter the array size: 5
Enter the array elements: -5 4 3 2 7
Sorted array is: -5 2 3 4 7
Example
29: Write a C program to find the length of given string.
Solution 29:
The program is as follows:
#include
main( )
{
char string[80], *ptr;
ptr = string;
printf(“\n\tEnter the string whose length you want:”);
while ((*ptr++ = getchar( )) != ‘\n’) /* read the string */
*- - ptr = ‘\0’;
printf(“\nString is %s”, string);
printf(\n Its length is %d”, (ptr – string));
}
OUTPUT (after running):
Enter the string whose length you want: Dr. RAJIV
String is Dr. RAJIV
Its length is 9
Example
30: Are the following expressions the same: *ptr++ and ++*ptr?
Solution 30:
No, they are not the same. *ptr++ increments the pointer and not the value pointed by it,
whereas ++*ptr increments the value being pointed to by ptr.
Example
Do'stlaringiz bilan baham: |