Discussion :: Command Line Arguments - Find Output of Program (Q.No.6)
|Sreepal V said: (Dec 18, 2010)|
|A command line argument is the
information that follows the program's name on the command line of the operating system. For
example, when you compile a program, you might type something like the following after the
program_name string1 string2 string3 ... (default syntax)
"program_name" "string1" "string2" "string3" ...(correct syntax)
|Anu said: (Dec 30, 2010)|
|Can someone explain about the output of the above program ?|
|Mary said: (Jan 10, 2011)|
|Why don't the output be sample?|
|Shamshad said: (Jan 27, 2011)|
|Why don't the output be "*.c" ?.|
|Chandrasekar said: (Feb 24, 2011)|
|Because printf starts from argv. So it starts from args passed into program.
"Sample" is the program name which is stored in argv
|Varun Gupta said: (Mar 18, 2011)|
|@Chandrasekar not a relevant explanation|
|Appireddy said: (Jun 2, 2011)|
|Any one can explain the output of the above program please.|
|Stillalone4U said: (Jun 30, 2011)|
only arg prints string !!
So "" not printed it prints only *.c
|Kavithha said: (Jul 17, 2011)|
|Since argv is a string, it print ly the string pointed by the argv i.e. *.c .|
|Anish said: (Aug 5, 2011)|
So it prints *.c
|Aloke said: (Aug 31, 2011)|
Where is the " " gone ?
Why they are missing please explain me ?
|Sundar said: (Aug 31, 2011)|
I would like to explain it with DOS commands.
C:\Program Files>cd windows media player
C:\Program Files\Windows Media Player>cd..
C:\Program Files>cd "windows media player"
C:\Program Files\Windows Media Player>
The above commands works perfectly in latest versions of DOS (after Windows 98).
But in previous versions of DOS we cannot use commands with white spaces in directly name like below:
c:\Program Files>cd windows media player
If you use like that it will say like "directory not found error". We should enclose the directory name with double quotes like given below:
c:\Program Files>cd "windows media player"
So, The DOS itself ignores the quotes (") and inputs only *.c to the program. This is the reason what you expected.
I hope this will help you! Have a nice day!!
|Raj said: (Sep 9, 2011)|
|Am getting the output as the list of files and folders in the current directory.Why is it so? Some one explain please.|
|Ram said: (May 7, 2012)|
|In above program no of arguments are 2..
now condition is for(i=1;i<2;i++) here condition is true
%S needs base adress to print a string we provided argc in printf ..hence the output becomes *.c
|Kompri said: (Aug 17, 2012)|
|Yogesh said: (Dec 3, 2012)|
|I'm facing more confusion my gcc compiler print :-sample *.c
But you are given output only *.c
How to print a :- *.c
If any one known please give me correct reason.
|Gcp said: (May 29, 2013)|
|Can anybody tell me what's with the int argv. How can characters be the elements of integer strings.|
|Shail said: (Jul 9, 2013)|
|Warning: format \'%s\' expects type \'char *\', but argument 2 has type \'int\'.|
|Mangusta said: (Aug 21, 2013)|
|Hey, But argument is char * argv, not char* *argv or char* argv.|
|Mangusta said: (Aug 21, 2013)|
|Disregard my last post, I have mistakenly seen int * argv as char * argv.
Inside "main", argv is treated as pointer and all further arithmetics performed upon it, will depend on actual type of this pointer.
It doesn't matter on 16- and 32-bit systems, if we use:
int * argv instead of char* * argv
Because sizeof(int) = sizeof(char *) on both, therefore argv[i] with (int * argv) will be equal to argv[i] with (char* * argv).
It however does matter on 64-bit and higher systems, because sizeof(int) = 4 but sizeof(char *) >= 8.
Therefore argv[i] with (int * argv) will not be equal to argv[i] with (char* * argv).
Post your comments here:
Email : (optional)
» Your comments will be displayed only after manual approval.