Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Command Line arguments in C

Status
Not open for further replies.

agent_009

Member level 2
Joined
Dec 17, 2006
Messages
47
Helped
10
Reputation
20
Reaction score
3
Trophy points
1,288
Activity points
1,563
In C, for command line arguments we use

1. int main(int argc, char *argv[])

2. int main(int argc, char *argv[0])

However both of them work fine

What is the exact difference between the two.

Thanx
 

Hi
as I know
there is no difference.
*argv[]=*argv[0]
regards
 

    agent_009

    Points: 2
    Helpful Answer Positive Rating
both works becase
*argv[]=*argv[0] have the same effect because when nothing is written in [] it means 0.
 

The is no difference between the two line, *argv[]and *argv[0] are exactly the same
 

When you pass an array you are really passing a pointer to the first element of the array so that *arg[], *arg[1], *arg[999] and **arg are all the same.
 

@sks5440,

sorry, but you are compl. wrong.

sks5440 said:
When you pass an array you are really passing a pointer to the first element of the array so that *arg[], *arg[1], *arg[999] and **arg are all the same.

exmpl.

1. a pointer to the first element of the array, looks like this (datatype *)&arg[0]
2. *arg[1] and esp. **arg ist the same ???, bullschitt !
3. what do you mean, arg[], *arg[1], *arg[999] and **arg are all the same ??, bullschitt !

functionname (int argc, char *argv[]) or functionname (int argc, char *argv[0]) means, argv is a pointer to the first entry of the array with unknown numer of item. Items are of type (char *).
so, the firts entry means, ther is no difference if you write *argv[] or *argv[0]

sorry, Rolf
 

Since the argument expects an address and since address of index 0 is same as the base address the value (or address) passed to the main function would be the same. Hence the result.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top