abt pointers in c

L

lifemom

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.
 
I

Ian Collins

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.
What's a qtn and a pgm?
 
A

Andrew Poelstra

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.

Here is a corrected version for the benefit of other members (I need to
rest my brain):

Hello,
This is my first post, as though that's even remotely relevant. One
of my friends was interviewed for a job as a C programmer, and was asked
to use pointers. Since she isn't actually qualified for the job, she
doesn't know what a pointer is. Could you please do her work for her?
She'd much appreciate getting a job she neither deserves nor anyone here
wants here to have.


And my response <censored>:
You... shouldn't be on... Usenet... moron... the answer is no.
 
B

Bill Pursell

Andrew said:
Here is a corrected version for the benefit of other members (I need to
rest my brain):

Hello,
This is my first post, as though that's even remotely relevant. One
of my friends was interviewed for a job as a C programmer, and was asked
to use pointers. Since she isn't actually qualified for the job, she
doesn't know what a pointer is. Could you please do her work for her?
She'd much appreciate getting a job she neither deserves nor anyone here
wants here to have.


And my response <censored>:
You... shouldn't be on... Usenet... moron... the answer is no.


Oh, be nice. To the OP (lifemom, "OP" refers to you): your question is
inappropriate, as it is extremely basic and you can probably find your
answer in section 4 of the FAQ, located at:
http://c-faq.com/ptrs/index.html.
 
N

Neil

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.

1.do not use SMS here.
2.Gimmee code, another no no.
3. do my home work no.

Assuming you you know what a pointer is. point to the last char in the
string. print 1 char at a time. decrement the pointer till you are done.
 
R

Richard Heathfield

Neil said:
Assuming you you know what a pointer is. point to the last char in the
string. print 1 char at a time. decrement the pointer till you are done.

That doesn't reverse the string. It merely prints it backwards.
 
R

Richard Heathfield

(e-mail address removed) said:
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.

I guess she didn't get the job, then.
they asked to do with help of pointers.can anyone write the pgm and
teach me.without using arrays.

Lots of people could do this - but what good would it do? We're glad to
help, but if you want us to do your programming /for/ you, we expect to be
paid. If you actually wish to learn, you will see the utility of trying to
solve the problem yourself, and posting the code here for our comments and
suggestions. We do not charge for that.
 
E

Eric Sosman

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."
 
V

Vladimir Oka

Eric said:
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.

So, IMHO, it is possible to do as per OP.
 
K

Keith Thompson

Vladimir Oka said:
Eric said:
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.

You can have an array without explicitly declaring an array object.
For example:

char *p = malloc(100);

p (if it's non-null) points to the first element of a 100-element
array of characters.

For that matter, the indexing operator is defined in terms of pointer
arithmetic, so in a sense using indexing operators doesn't violate the
terms any more than using pointers would.
So, IMHO, it is possible to do as per OP.

Only if the problem is defined more clearly.
 
V

Vladimir Oka

Keith Thompson opined:
Vladimir Oka said:
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.

You can have an array without explicitly declaring an array object.
For example:

char *p = malloc(100);

p (if it's non-null) points to the first element of a 100-element
array of characters.

For that matter, the indexing operator is defined in terms of pointer
arithmetic, so in a sense using indexing operators doesn't violate
the terms any more than using pointers would.
So, IMHO, it is possible to do as per OP.

Only if the problem is defined more clearly.

If it was, we wouldn't be still here, discussing it. ;-)

I assumed that "array" meant something declared as:

char a[] = "Hello, World!";

Which I thought is a reasonable assumption for an interview question.
 
S

shariq_tariq

lifemom i think you should be reading examples all across the web. The
link that Bill has provided is a pretty decent starting point. This
forum would be immensely more helpful for you if you got some sort of
start on the program and were stuck

Thank You

Shariq
 
V

Vladimir Oka

lifemom i think you should be reading examples all across the web. The
link that Bill has provided is a pretty decent starting point.

What are you talking about? What link?
Quote context (what you're replying to and who said it).
If you're using Google, click on Show Options, and then Reply link that
appears.
This forum would be immensely more helpful for you if you got some sort of
start on the program and were stuck

This is not a forum. This is a Usenet newsgroup. There's a world of
difference.
 
K

Keith Thompson

Vladimir Oka said:
(e-mail address removed) wrote: [...]
This forum would be immensely more helpful for you if you got some sort of
start on the program and were stuck

This is not a forum. This is a Usenet newsgroup. There's a world of
difference.

"Forum" is a generic term. A Usenet newsgroup is one of many kinds of
forum.
 
A

Andrew Poelstra

Keith said:
Vladimir Oka said:
(e-mail address removed) wrote: [...]
This forum would be immensely more helpful for you if you got some sort of
start on the program and were stuck
This is not a forum. This is a Usenet newsgroup. There's a world of
difference.

"Forum" is a generic term. A Usenet newsgroup is one of many kinds of
forum.
By 'forum' I'm sure he meant 'message board'. I'm sure you knew that,
but I thought that I'd make the distinction clear to other people.

--
Every prime number in a series as a joke
Made all the patterns clear when I took that final toke
A whole lot of funny scribbles define our universe
And yet the numbers still make me oh so high
-- Numbers (Sunken Complexity)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,965
Members
47,511
Latest member
svareza

Latest Threads

Top