Discussion :: Command Line Arguments - Find Output of Program (Q.No.2)
|Hariom said: (Oct 21, 2010)|
++argv means argv
thats why argv = one
because of print string answer is one.
|Jyotiranjan said: (Feb 21, 2011)|
|Execution start from right argv could not increased. Compiler will take the value first then increment. As first value was one.
So answer is one.
|Vidi said: (Jun 14, 2011)|
|Can anyone elaborate on : char **argv used.|
|Ankur said: (Jul 1, 2011)|
|Can someone explain this output in detail ?|
|Sholvi.. said: (Sep 25, 2011)|
|I think here ...
argv means *argv and *argv=**argv
argv or *argv contains address of string "myprog"
When we increament *argv it tends to next value stored as:
and as we can see in printf()=>"%s" is used so it will print the value of argv
and we will get the ans:
|Rathika.B said: (Jan 16, 2012)|
|All mention only about argv. Then what about argc? what it can do here? & in function definition must match the parameters passing in command prompt. But we directly declare the strings here as one two three then how it accept?|
|Saurabh said: (Mar 8, 2012)|
|**argv is another notation for 2D array.
argv = address of 1st row
++argv = address of first row n end of 1st rows column
*++argv = value in first row
Thus output is: one
|Rock said: (Dec 28, 2012)|
myprog is program name;
First pointer execute and after printing it will increase.
So answer is one.
|Priya said: (Feb 12, 2013)|
|Why is the argc mentioned here unnecessarily?|
|Rajashekar said: (Nov 10, 2013)|
|Essentially argv always points to the arguments that have been entered on the command line and argc holds the no of arguments entered on the command line.
>>For every program ,program name itself is an argument that is passed to the OS to execute, so for any program always the first argument would always be the program name like:"c\users\tc\bin\hello.c"
>>So the arguments that later follow the program name are the rest of the arguments that are indexed by argv in order which they are entered.
argv = myprog
argv = one
argv = two
argv = three
>>So *++argv corresponds to argv i.e===>one.
|Klobin said: (Nov 14, 2013)|
|argc is 4 here as ---- myprogs is also considered as no.1.
So the total becomes four ---- argument counter will get value:4.
|Ganesh Sable Jtc said: (Jun 29, 2014)|
|Rule of pointer *p++ is increment address.
Suppose int *p++ address is 2000 then increment 2004 because pointer size 4.
And *++p is increment actual value suppose 456 in array so display 5.
|Abhinav Kumar said: (May 8, 2016)|
|**++argv should be used instead of *++argv.|
|Vinayak Tapkir said: (Dec 3, 2017)|
|Answer is wrong beacause first argument contains file executable name. Ao after incrementing it must print 1st provided argument on command line.|
|Anshu said: (Aug 28, 2018)|
|Good explanation, Thanks @Sholvi.|
Post your comments here:
Email : (optional)
» Your comments will be displayed only after manual approval.