LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-17-2005, 03:53 AM   #1
TruongAn
Member
 
Registered: Dec 2004
Location: Vietnam (Việt Nam)
Distribution: Gentoo (desktop), Arch linux (laptop)
Posts: 728

Rep: Reputation: 33
Check agruments passing in C++,


Hello everyone,

I am a windows' VB programmer, so either
linux programing or C++ is new to me.

when I use KDevelop to create a simple
console program, The main function is auto
declared like this:

int main (int argc, char * argv[]) {

};.

I know that the declaration: char * variablesname
is used to declare a pointer; the declaration
char variablesname[] is used to declare a array.
and I hear that pointer, some how, is a special kind
of arrays.

So that what does the declaration char * argv[] means?
How can I access to the agruments pass to my program?
 
Old 06-17-2005, 04:06 AM   #2
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
char *argv[] is an array of char pointers. A pointer can be seen as equivalent to an array, storing the address of the first element. In this case, what you've got is an array of strings. Each of your program's arguments will be held in an element of this array. For example, if you called your program as "foo arg1 arg2", then the array would have the following contents:

argv[0] = "foo"
argv[1] = "arg1"
argv[2] = "arg2"

The argc variable contains the number of arguments to the program, and in this case would be 3. It's very important that you use this value to make sure you don't go past the end of the array.
 
  


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
Command Line agruments lazyuser Programming 2 05-06-2005 01:34 AM
FC3 Downloads not Passing Integrity Check harley51 Fedora 12 02-02-2005 04:37 PM
Partition check, check double check Vincentius Linux - General 0 12-25-2004 05:47 AM
passing passing variable in Java as reference djgerbavore Programming 3 11-10-2004 02:18 PM
Boot disk; check. CD in drive; check. Doesn't work; check. Hal DamnSmallLinux 7 02-04-2004 02:10 AM

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

All times are GMT -5. The time now is 08:30 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