if we have a declaration
int arr[] = { 1,2,3,4,5};
int *ptr;
what is the diff betn ptr = &a and ptr = a ;
when i do
ptr = &a ;
or ptr = a ;
and then ptr += 2 ;
then *ptr points to 3 in both cases
Basically , my doubt is whether the statement " array name is same as
the address of array " true in all cases without exception and can both
be used interchangebly ..??
kind regards
rahul 4 2671 ra************* ******@gmail.co m wrote:
if we have a declaration
int arr[] = { 1,2,3,4,5};
int *ptr;
what is the diff betn ptr = &a and ptr = a ;
See the thread 'C Strings not returning from a function' from earlier today.
--
Ian Collins. ra************* ******@gmail.co m wrote:
if we have a declaration
int arr[] = { 1,2,3,4,5};
int *ptr;
what is the diff betn ptr = &a and ptr = a ;
You will get warning in 'ptr = &a'
"warning: initialization from incompatible pointer type"
and you wont get warning in 'ptr = a'
Basically, &a return pointer to array of integer of size 5. And , a
return pointer to integer.
We can experiment this by following statements;
( (unsigned long )(&a + 1) - (unsigned long )(&a) ) , this will
return 5 * 4 = 20 (Assume : sizeof(int )= 4 )
and
( (unsigned long )(a + 1) - (unsigned long )(a) ) will return 4;
#include<stdio. h>
int main()
{
int a[5];
int *ptr = a;
int *ptr1 = &a ;/*warning: initialization from incompatible
pointer type*/
int (*ptr2)[5] = &a;
printf("%d\n",( int) ( (unsigned long )(&a + 1) - (unsigned
long )(&a) ) );
printf("%d\n",( int) ( (unsigned long )(a + 1 ) - (unsigned
long )(a ) ) );
return 0;
} ra************* ******@gmail.co m wrote:
if we have a declaration
int arr[] = { 1,2,3,4,5};
int *ptr;
what is the diff betn ptr = &a and ptr = a ;
Their types. See c-faq.com, sec 6.12.
when i do
ptr = &a ;
or ptr = a ;
and then ptr += 2 ;
then *ptr points to 3 in both cases
Basically , my doubt is whether the statement " array name is same as
the address of array " true in all cases without exception and can both
be used interchangebly ..??
Array name in expression is the address its initial element in some
context.
On 25 Sep 2006 22:23:27 -0700, "ra************ *******@gmail.c om"
<ra************ *******@gmail.c omwrote in comp.lang.c:
if we have a declaration
int arr[] = { 1,2,3,4,5};
int *ptr;
what is the diff betn ptr = &a and ptr = a ;
when i do
ptr = &a ;
If you code this, your compiler is required to issue a diagnostic. If
it does not, your compiler is not (or is not being invoked in) a
standard conforming mode.
or ptr = a ;
and then ptr += 2 ;
then *ptr points to 3 in both cases
Basically , my doubt is whether the statement " array name is same as
the address of array " true in all cases without exception and can both
Who made the (incorrect) statement that " array name is the same as
address of the array "? What are their qualifications to make such
statements? Why should we believe him/her/them? He/she/they are
quite wrong in this case.
be used interchangebly ..??
kind regards
rahul
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: BadOmen |
last post by:
I have made an array in a function in a Class now I need to get to that
Array from an other function in an other Class, How do I do that?
The Array has no fixed size as it is dependent on how much a user has put in
a txt file.
The Class with the Array is an object, objInternetClass and I want to reach
the Array by doing something like...
|
by: jlopes |
last post by:
There seems to bet no diff between a vitual method and an inheirited method.
class A_Base
{
public:
virtual void filter(){ /* some code */ }
};
class D_of_A_Base : public A_Base
{
|
by: iceColdFire |
last post by:
Hi,
What is the Diff btwn Function overloading and overriding
thanks,
a.a.cpp
|
by: Martin Altschwager |
last post by:
Hi,
I desperately need some help with what I assume to be a minor problem
that I just can't solve.
I'm writing a page where on mouseover a link, an image needs to be
displayed and some text, which is defined inside an array, sould
appear inside a table cell (whose id is "tdDesc").
That's basically what's in the HTML-file:
|
by: ehames |
last post by:
Hi guys,
As far as I know, for any type T, and positive integer N, if I have an
array declared as:
T array;
then,
&array and array are the same element. Is there any reason why a
| |
by: Andreas Kasparek |
last post by:
Hola!
I'm preparing my master thesis about a XML Merge Tool implementation and was
wondering if there is any open standard for XML diff regarding topics like:
- is a diff result computed on the ordered or unordered xml node tree of
the compared documents?
- what identifiers/criteria should be used by default to match elements of
the same...
|
by: Csaba Gabor |
last post by:
I'm comparing the text of (snippets of) web pages which I expect to be
quite different or quite similar. In the case where they are similar,
I would like to display the more recent one and say something like:
Word 2 added : "Jack be nimble"
Words 10-11 changed to: "the quick brown fox"
: "the brown fast quick fox"
Words before word 20...
|
by: dadevil |
last post by:
Hi guys, this is my first post around here, and here it goes
I need to create an array to store info about a number "n" of persons, so i create this structure ( each person have one name and one adress)
__value stuct person{ // is this correct? ("__value")
string name;
string adress;
}
|
by: TechnoAtif |
last post by:
Hi ALL
I have entered some array values using checkboxes into mysql database through a form. Next iam creating a searchpage where all those cateogories inserted through checkboxes has to be retrieved using list/menu box.
When i check only a single checkbox to insert the checked category ,selecting that category through list box gives out the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |