This is a discussion on Garbage Value Output within the C and C++ forums, part of the Programming Talk category; I have my C program as below: void main() { int testarray[2]={1,2}; int *ar = &testarray[-1]; int ...
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I have my C program as below:
void main() { int testarray[2]={1,2}; int *ar = &testarray[-1]; int j; for(j=0;j<2;j++) { printf("\t%d",*ar); ar++; } } When I run the above program it gives some garbage value. Can anyone tell me why I get garbage value as output for the above program? |
|
|||
|
You get some garbage value as output because the array in C programming starts at index 0 and in the statement
int *ar = &testarray[-1]; The address of testarray[-1] is stored in the ar and the contents when it is printed in the output statement gives a garbage value. |
![]() |
| Thread Tools | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C Programming - Managing Input and Output Operations | JobHelper | Career Advice | 0 | 04-15-2006 08:30 AM |
| Controlling PHP Output: Caching and compressing dynamic pages | techguru | Unix Articles and Tutorials | 0 | 08-28-2005 11:26 AM |
| Aditi Technologies C Test | JobHelper | Placement Papers | 0 | 05-04-2005 09:03 AM |
| Solaris x86 FAQ 2/2 | Dan Anderson | Tech FAQ | 0 | 04-27-2004 08:24 PM |
| [gnu.bash.bug] BASH Frequently-Asked Questions (FAQ version 3.26) | Chet Ramey | Tech FAQ | 0 | 04-26-2004 11:00 AM |