LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 09-27-2007, 08:03 AM   #1
psandeepnair1985
LQ Newbie
 
Registered: Mar 2007
Posts: 9

Rep: Reputation: 0
Question Doubt in arrays


Hi friends,

I have a major doubt in array concept.
For eg i declare
int a[10];
int b[10][10];

I am confused how &a and a are equal (&a = a)
and
how &b=b=*b..................

I would be thankful to any one who could explain me the logic behind this....

Please help friends.......
 
Old 09-27-2007, 08:28 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
First, what language? (looks like C)
Quote:
I am confused how &a and a are equal (&a = a)
They are not equal!!.....I don't understand this question. "&a" means the address of the variable named "a". In the case of an array, the name is the address of the first element. You get the value with either a[n] or *a[..]
 
Old 09-27-2007, 08:46 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
array[10][10] is equivalent to array[100]
there is no real 3D in an array of memory obviously,
it's just syntax.

like:
Code:
#include <stdio.h>



main()
{
    char a[10];
    char b[10][10];

    printf("sizeof a = %d\n", sizeof a);
    printf("sizeof b = %d\n", sizeof b);
}
Code:
billym.primadtpdev>make 1 && ./1
gcc     1.c   -o 1
sizeof a = 10
sizeof b = 100
 
  


Reply



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
Arrays in C rubadub Programming 1 07-30-2007 02:26 PM
Arrays baks Programming 2 03-19-2007 12:32 AM
Question about outputing arrays with pointers, then just arrays... RHLinuxGUY Programming 1 04-12-2006 05:40 AM
Arrays in C++ kalleanka Programming 5 02-07-2004 12:27 AM
help with arrays leroy27336 Programming 6 01-20-2004 06:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:35 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
Open Source Consulting | Domain Registration