Interview Question

Software Engineer Interview Hyderābād (India)

Whats is the difference between these two ? char* p

  = "Hello"; char* q = {'h', 'e', 'l', 'l', 'o'};
Tags:
c language
Answer

Interview Answer

1 Answer

0

first one is a character string, C automatically adds null character in the end. And it needs to be "const char* p" instead of just "char*" because compiler may put this on read only memory. You can never guarantee that it can be modified later. (but interviewer was least interested in knowing that)

Interview Candidate on May 17, 2012

Add Answers or Comments

To comment on this question, Sign In with Facebook or Sign Up