473,396 Members | 1,814 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,396 software developers and data experts.

how to write in terms of reference ?

main(int argc, char *argv[])

the second parameter, argv, to function main takes a pointer to an array.

can we also write it in terms of a reference rather than a pointer ? (like &..)
Jul 22 '05 #1
4 3416
On 30 Jun 2004 19:50:00 -0700, se********@yahoo.com (m sergei) wrote
in comp.lang.c++:
main(int argc, char *argv[])

the second parameter, argv, to function main takes a pointer to an array.

can we also write it in terms of a reference rather than a pointer ? (like &..)


No, a pointer is not a reference, and a reference is not a pointer.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 22 '05 #2
> main(int argc, char *argv[])

the second parameter, argv, to function main takes a pointer to an array.

can we also write it in terms of a reference rather than a pointer ? (like

&..)

The main function has been defined to have those parameters, and you can not
change that definition.
In addition argv is an array and arrays can not be referenced as a reference
can not be indexed.

Niels Dybdahl

Jul 22 '05 #3
m sergei wrote:
main(int argc, char *argv[])

the second parameter, argv, to function main takes a pointer to an
array.
No, it doesn't. It takes a pointer to a pointer.

can we also write it in terms of a reference rather than a pointer ?
(like &..)


If you mean whether you can write main in such a way that it takes a
reference to an array, the answer is no (typically).
If you mean whether you can use a reference to an array as function
parameter in general, the answer is yes:

#include <iostream>

void foo(int (&x)[3])
{
x[0] = 1;
x[1] = 2;
x[2] = 3;
}

int main()
{
int array[3];
foo(array);
std::cout << array[0] << ' ' << array[1] << ' ' << array[2] << '\n';
}
Jul 22 '05 #4
m sergei posted:
main(int argc, char *argv[])

the second parameter, argv, to function main takes a pointer to an
array.

can we also write it in terms of a reference rather than a pointer ?
(like &..)

I know that in your own head you may just think of a reference as a const
pointer, and this is may even be the way a certain compiler works with them
in certain places, but the thing is that it doesn't have to, the Standard
does specify how the behaviour of references is to be achieved, just *that*
it is achieved. For example:

int main()
{
double k;

double& p = k;

p = 53.2342;
}
There won't be a pointer there.
-JKop
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: lkrubner | last post by:
I've written some template code and one thing I'm trying to protect against is references to images that don't exist. Because users have the ability to muck around with the templates after...
10
by: Greg Hurlman | last post by:
I've got what I'm sure is a very simple problem. In an ASP page, I am trying to write out 4 fields from a recordset in succession: Response.Write rs("LastName") Response.Write rs("Suffix")...
2
by: Rob McLennan - ZETLAND | last post by:
Hi, I'm relatively clueless when it comes to correct ASP syntax. I'm testing out a search form for my company's website which is done in ASP. The results are displayed as per the code shown at the...
7
by: Ian Shere | last post by:
I have an FAQ page on my site, but, because much of the information could be relative to the area council's bylaws, I want to have a pop-up window appear when someone clicks the "FAQ's" menu...
10
by: Kristian Nybo | last post by:
Hi, I'm writing a simple image file exporter as part of a school project, and I would like to write completely platform-independent code if at all possible. The problem I've run into is that...
27
by: Sune | last post by:
Hi! Pre-requisites: ------------------- 1) Consider I'm about to write a quite large program. Say 500 K lines. 2) Part of this code will consist of 50 structs with, say, no more than at most...
15
by: seema_coma | last post by:
Hi all, I am new to C programming, All I just need to know is how to write the following in C, if (open STDOUT){ close the STDOUT } Can anyone guide me Thanks
14
by: Jeroen | last post by:
Hi all, I've got a question about writing a library. Let me characterize that library by the following: * there is a class A which is available to the user * there is a class B that is used...
36
by: CK | last post by:
How do I write a set based query? I have a groupSets table with fields setId, idField, datasource, nameField, prefix, active Data: 1,someIDfield, someTable, someField, pre1, 1 2,someotherIDfield,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.