473,405 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Confused about this question!!

14
Hello,

I need assistance on this question.

Suppose that a is a one-dimensional array and p is a pointer variable. Assuming that the assignment p = a has just been performed, which of the following expressions are illegal because of mismatched types? Of the remaining expressions, which are true (have a nonzero value)?

a) p == a[0]
b) p == &a[o]
c) *p == a[0]
d) p[0] == a [0]


I assume that b and d are true from the given information. I just need a little clarification on the definitions of the given equations - the book fails to give any pre-existing examples to help tackle the problem.

Thanks.
Jun 18 '09 #1
5 3129
newb16
687 512MB
b) is also true if you replace letter 'o with zero - p points to the first item in array that is address (&) of the first item of the array.
Jun 19 '09 #2
JosAH
11,448 Expert 8TB
Answer c) is also correct

kind regards,

Jos
Jun 19 '09 #3
donbock
2,426 Expert 2GB
Your first question was which of the expressions are illegal due to mismatched types. We already know that expressions (b), (c), and (d) must be legal since it has already been established that they all evaluate to a nonzero value.

Expression (a) is illegal because it attempts to compare a pointer to the thing being pointed at ... unless the elements of the array are of type 'void *'. Expression (a) would even evaluate to a nonzero value if each element of the array (or at least the first one) contained its own address.

By the way, the legality of (c) and (d) depend on what type of pointer variable p is declared as. These expressions are illegal if p is declared as a 'void *' because in that case there would be no way to dereference the pointer.

So ... my conclusion is that only expression (b) is definitively legal. The legality of the other expressions can't be determined without making assumptions that aren't given in the problem statement.
Jun 19 '09 #4
stayit
14
Ah. Now I understand. Thanks!
Jun 19 '09 #5
donbock
2,426 Expert 2GB
By the way, C and C++ have different rules for whether a legal statement can implictly convert between a specific pointer type and a 'void *' pointer type. That means the answer to your question is subtly different for the two languages.
Jun 19 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: ALI | last post by:
hi i need some best answer's for this question for interview as an oracle (DBA). Q : what is the most difficult situation u faced and how did u solved it ???? i really appriciate if some...
2
by: John | last post by:
Hi all, I really don't know where to post this question but it is urgent and I need resolution on this. I just re-installed my Windows since it was just downloading something from the...
0
by: mirandacascade | last post by:
Operating system: Win XP Version of Python: 2.4 I recognize that this question is not about Python...it has only a tangential Python connection. I'm using a Python package to run a process;...
1
by: omid1980 | last post by:
hi I have an examination and i shuld answer this question please help me. Explain the advantages of using XML with a database for ecommerce sites?
1
by: chb1980 | last post by:
hi..iam trying to handle this one ..but..i have no idea and don't know how to approach it .. the following data has in it which is large relative to rounding errors . find the noise and change...
1
by: oracle newbie | last post by:
What could this question (below) be asking about? This statistics shows how many users access the Library Website Home Page. Page Access statistics is recorded by on a monthly basis. Users may...
3
by: Roopanwita | last post by:
Hi, I am asking a very basic question. Can anyone explain me the difference between Having & Where Clause. Thanks in advance, Roopanwita
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.