Re: What's the position of pointers



   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


.



Relevant Pages

  • Re: Whats the position of pointers
    ... If you are able to solve it without using the pointers, ... couldn't have made if you'd bothered to compile your code before ... without bothering to compile it.) ... You mean that the code shouldn't *directly* modify a. ...
    (comp.lang.c)
  • com interop C# VB6
    ... but when we now try to compile ... the c# projects they fail - invalid reference and the changed VB6 DLLs are ... references - (create the new com wrapper - modify the reference in the ...
    (microsoft.public.dotnet.faqs)
  • Re: Assigning to references
    ... > This fails to compile with a message that operator= is inaccessible. ... > should this be a problem since I'm trying to assign to a reference? ... references are *NOT* pointers. ... you initialise it and use it like any other ...
    (comp.lang.cpp)
  • Re: pointer
    ... b->foo2(pPointer); ... Would this compile? ... pointer (not double pointers or reference to pointers) be just fine? ...
    (microsoft.public.vc.mfc)
  • Re: Ginastub domain list
    ... I am interested in how you hooked the callback functions. ... modify the pointers in the pWinLogonFunctions dispatch table? ... > populates the domain list, or how to set the combobox the way I want to. ...
    (microsoft.public.platformsdk.security)