473,322 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Pointer pointing itself giving different value

8
hi frnds. while studying pointers, i came across this example from a book ...
here ...at the end z is assigned address of itself by **v,
how **z can give value 3.15 if it is addressing itself ?????? another Q is if if **z
is printed in the next line after printing value of z ....it doesn't give value 3.14....
is it something related to scope??.....confused.
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <conio.h>
  3. float a=3.15;
  4. float **z;
  5. float **y;
  6. float ***x;
  7. float ****v;
  8. float ****w;
  9. float **fun1(float*);
  10. float ****fun2(float***);
  11. void main()
  12. {
  13. z=fun1(&a);
  14. printf("%u , %f",z,**z);
  15.   getch();
  16. }
  17. float **fun1(float*z)
  18. {
  19.  y=&z;
  20.  v=fun2(&y);
  21.  return (**v);
  22. }
  23. float ****fun2(float***x)
  24. {
  25.  w=&x;
  26.  return(w);
  27. }
Jun 16 '07 #1
4 1538
weaknessforcats
9,208 Expert Mod 8TB
Glad you are confused. It turns out that once you go past pointer-to-pointer
Expand|Select|Wrap|Line Numbers
  1. char** ptr;
  2.  
The mind breaks down and visualization of what happens is not possible.

If you use anything beyond pointer-to-pointer in code on a real job, you will be taken to a back room and chastized by the application of the coding standards manual to your hinder parts.

The author of your book is merely having fun with you.
Jun 17 '07 #2
axneer
8
Glad you are confused. It turns out that once you go past pointer-to-pointer
Expand|Select|Wrap|Line Numbers
  1. char** ptr;
  2.  
The mind breaks down and visualization of what happens is not possible.

If you use anything beyond pointer-to-pointer in code on a real job, you will be taken to a back room and chastized by the application of the coding standards manual to your hinder parts.

The author of your book is merely having fun with you.
Thank you Weaknessforcats for the response,but I want to know does pointers behaves specifically in these kind of examples or behaves randomly that we can not imagine
.( I ran the program "stepwise " , "watching " the addresses
it is giving and it is true that I was not able to imagine how address is changing .
I know this would be ridiculous to apply to any real-job)
But does it behave specifically? (any specific pattern of change going inside memory?)
I will be vary thankful to you for your reply.....
Jun 18 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
There are no bizarre goings-on.

Expand|Select|Wrap|Line Numbers
  1. char* adr   is the address of a char
  2.        *adr    is the variable
  3. char** adr1 is the address of a char*
  4.         *adr1 is the char*
  5.        **adr1 is the variable
  6. char*** adr2  is the addres of a char**
  7.        *adr2 is the addrss of a char*
  8.        **adr2 is the address of a char
  9.        ***adr2 is the char
  10.  
If you have five layers of indirection:
Expand|Select|Wrap|Line Numbers
  1. char***** adr;
  2.  
Then you need five dereferences to arrive at the variable:
Expand|Select|Wrap|Line Numbers
  1. printf("%c", *****adr);
  2.  
Jun 18 '07 #4
axneer
8
There are no bizarre goings-on.

Expand|Select|Wrap|Line Numbers
  1. char* adr   is the address of a char
  2.        *adr    is the variable
  3. char** adr1 is the address of a char*
  4.         *adr1 is the char*
  5.        **adr1 is the variable
  6. char*** adr2  is the addres of a char**
  7.        *adr2 is the addrss of a char*
  8.        **adr2 is the address of a char
  9.        ***adr2 is the char
  10.  
Thank you for response .. I just removed one block about pointers from my brain
Jun 18 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Newsgroup - Ann | last post by:
Gurus, I have the following implementation of a member function: class A { // ... virtual double func(double v); void caller(int i, int j, double (* callee)(double)); void foo() {caller(1,...
13
by: xuatla | last post by:
I encountered "segmentation fault" and I checked my code, found the following problem: I want to reallocate memory for an array. I defined the following function: int reallocateMemory( double...
0
by: Anupam | last post by:
In article <D8sq9J.HKx@alamo.net>, Briggs Reschke <briggs@alamo.net> wrote: >The following code fragment is a little puzzle a friend passed on to me ( >The origionators name is Christopher...
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
8
by: Sam | last post by:
I have a situation occuring in my code and I just can't see to figure out why I have an structure called employee that will put all of the employee id's into a char array set to 10 struct...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.