This is a discussion on Pointer Problem within the C and C++ forums, part of the Programming Talk category; I have my C program code as below: #include <stdio.h> main() { int *x; ... .... } My doubt is I ...
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Pointer Problem
I have my C program code as below:
#include <stdio.h> main() { int *x; ... .... } My doubt is I want to pass address of x to a function named as test as below test(&x) that is pass by reference. Can I pass this without initializing the pointer x or do I need to initialize pointer and then pass the address. How can I initialize if I need to do that. Kindly help me. |
|
|||
|
You must initialize pointer and then only send it to the function as pass by reference. This is because to prevent the usage of garbage values in memory. You can initialize pointers by assigning it to NULL. In your example you need to assign the pointer x as NULL.
|
![]() |
| Thread Tools | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) | Steve Summit | Tech FAQ | 0 | 06-15-2004 07:00 AM |
| comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) | Steve Summit | Tech FAQ | 0 | 06-01-2004 07:01 AM |
| comp.lang.c FAQ list Table of Contents | Steve Summit | Tech FAQ | 0 | 06-01-2004 07:00 AM |
| comp.lang.c Answers to Frequently Asked Questions (FAQ List) | Steve Summit | Tech FAQ | 0 | 06-01-2004 07:00 AM |
| comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) | Steve Summit | Tech FAQ | 0 | 05-15-2004 07:00 AM |