Eric said:
(e-mail address removed) wrote:
hi ,
im new to this group.
one of my friend attended an interview and she got a qtn of
writing a pgm to reverse a string.
they asked to do with help of pointers.can anyone write the pgm
and teach me.without using arrays.
It was a trick question, one with no solution. The
reason is simple: A string is an array, so there is no
way to reverse a string (indeed, to do anything at all
with a string) "without using arrays."
Now you got me intrigued...
I would have though strings are not necessarily arrays. I always
think of C strings as "zero-terminated sequence of characters", not
something you declare as an array. We keep telling people `char *c`
is different from `char c[]`.
I mean, you can declare a pointer, allocate some memory for it to
point to, fill that memory with zero-terminated sequence of
characters, all with just using pointers (i.e. not declaring any
arrays, nor using indexing syntax). What you end up with, I'd still
call a (C) string.