Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
main()
{
    char *name;
    int  length;
    char *cptr = name;
    name = "DELHI";
    printf {"%s\n", name};
    while{*cptr != '\0'}
    {
     printf{"%C is stored at address %u\n", *cptr, cptr};
     cptr++;
     }
     length = cptr - name;
     printf{"\nLength of the string = %d\n", length};
}
Posted
Updated 25-Mar-15 1:22am
v2
Comments
barneyman 25-Mar-15 8:22am    
interview question?

Fixed for you.
C
#include <stdio.h>

int main()
{
    char *name;
    name = "DELHI";
    int  length;
    char *cptr = name;
    printf ("%s\n", name);
    while(*cptr != '\0')
    {
      printf("%C is stored at address %p\n", *cptr, cptr);
      cptr++;
    }
    length = cptr - name;
    printf("\nLength of the string = %d\n", length);
  return 0;
}


By the way, you really like curly braces, don't you?
 
Share this answer
 
You systematically misplaced "{" and "}"

Line 7: printf {"%s\n", name}; -> printf ("%s\n", name);
Line 8: while{*cptr != '\0'} -> while(*cptr != '\0')
Line 10: printf{"%C is stored at address %u\n", *cptr, cptr}; -> printf("%C is stored at address %u\n", *cptr, cptr);

Line 14: printf{"\nLength of the string = %d\n", length}; -> printf("\nLength of the string = %d\n", length);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900