Re: What's the position of pointers
- From: sh.vipin@xxxxxxxxx
- Date: Sat, 13 Sep 2008 18:40:31 -0700 (PDT)
printf("\n Value of a is %d",a);
You have a call to printf. Where's the required #include <stdio.h>?
I don't know where this bizarre habit of putting the "\n" at the
beginning of a line rather than at the end came from. This prints an
unnecessary blank line, and fails to properly terminate the output
line.
Printing a blank line in beginning might be personal preference too,
but i certainly would like to know
what causes failure to properly terminate the output line.
It's spelled "return". Sure, it's a minor error, but one that you
couldn't have made if you'd bothered to compile your code before
posting it. (Some of my own dumbest mistakes here have been the
result of assuming I could just write code off the top of my head
without bothering to compile it.)
yea, i didn't compile before posting. My mistake. I will take care of
it in future.
you have to write the code such that without modifying the variable
"a" in main, value of "a" becomes 20. That is the output of program
when run is as shown in desired output.
It's not possible for the value of a to become 20 unless you modify
it. You mean that the code shouldn't *directly* modify a.
I mentioned without modifying the variable "a" in main. Probably I
should have been more specific here by saying
you have to write the code such that
- you do not modify the variable "a" in function main i.e. you can not
assign any value to variable "a" in function main
- line immediately after call to function X [printf("\n Value of a is
%d",a);] in function main should print as below
Value of a is 20
That will also stop Richard Heathfield's solution without using
pointers from being an answer to this puzzle.
Once you finish this, you will realize that there are many cases/
problems which cann;t be solved without using the pointers.
It's probably better just to read about pointers in some good tutorial
or reference work, such as K&R2.
Did that come after seeing Richard's Solution or you think there still
can be a solution without using call by reference here. I agree call
be reference is actually call be value only in "C" but want to explore
you more on this.
--
vIpIn
.
- Follow-Ups:
- Re: What's the position of pointers
- From: Flash Gordon
- Re: What's the position of pointers
- From: Keith Thompson
- Re: What's the position of pointers
- References:
- What's the position of pointers
- From: Yee.Chuang
- Re: What's the position of pointers
- From: sh . vipin
- Re: What's the position of pointers
- From: Keith Thompson
- What's the position of pointers
- Prev by Date: Re: calling qsort
- Next by Date: Re: Ex 7-5
- Previous by thread: Re: What's the position of pointers
- Next by thread: Re: What's the position of pointers
- Index(es):
Relevant Pages
|