LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 08-06-2004, 10:05 PM   #1
shams
Member
 
Registered: Jan 2004
Posts: 400

Rep: Reputation: 30
Unhappy error code for pointers and 2-Dimensional arrays


hi,
This is the code for pointers and 2-Dimensional arrays :
#include <stdio.h>
main()
{
int s[5][2]={
{1235,56},
{1212,33},
{1434,80},
{1312,78}

};

int i, j;

for(i=0;i<=3;i++)
printf(" Address of %d th 1-D array=%u\n",s[i],s[i]);

}
the output of this program suppose to be:
Address of 0 th 1-D array=3221222672
Address of 1 th 1-D array=3221222680
Address of 2 th 1-D array=3221222688
Address of 3 th 1-D array=3221222696
but it is:
Address of -1073744624 th 1-D array=3221222672
Address of -1073744616 th 1-D array=3221222680
Address of -1073744608 th 1-D array=3221222688
Address of -1073744600 th 1-D array=3221222696
plz point me where is the error.
 
Old 08-06-2004, 11:00 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Change this:
Code:
printf(" Address of %d th 1-D array=%u\n", s[i],s[i]);
to this:
Code:
printf(" Address of %d th 1-D array=%u\n", i, s[i][1]);

Last edited by Hko; 08-06-2004 at 11:05 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Double pointers and two dimensional arrays in C kponenation Programming 23 03-16-2011 12:43 PM
help with c++ code/pointers/arrays drisay Programming 1 01-28-2005 09:24 AM
Looking for a safe and efficient way to use two dimensional arrays. George2 Programming 6 03-22-2004 03:19 AM
help w/ pointers vs arrays PTBmilo Programming 3 04-10-2003 06:13 PM
C Question: arrays and pointers tundra Programming 7 07-19-2002 04:38 AM


All times are GMT -5. The time now is 05:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration