Discussion :: Command Line Arguments - Find Output of Program (Q.No.4)
|Aishwarya said: (Dec 3, 2010)|
|The 'argc' contains count value and argv contains "Good".
On printing argc,argv,its o/p will be 3 Good.
Because count value is 3 here.
|Xyz said: (Dec 27, 2010)|
|But sample is file name right arguments are given after file name is specified then good =0,morning =1 .. I don't understand if sample is argument here.|
|Sundar said: (Mar 22, 2011)|
|The given answer is correct. I have tested it.
argc - will contain 3 (count of arguments argv)
argv = C:\TURBOC\SAMPLE.EXE
argv = Good
argv = Morning
Therefore, answer is "3 Good"
|Prasastha said: (Jun 29, 2011)|
|argc=argument count= sample,good,morning=3
argv=by default it stores base address= it stores file name=sample
|Vidhya Balan said: (Jan 6, 2012)|
|Tell me - what is command line argument?|
|Sundar said: (Jan 6, 2012)|
Assume your current working directory in DOS is "C:\TURBOC" and your C program name is SAMPLE.C (which is in c:\turboc directory).
If you compile the program successfully, an EXE file SAMPLE.EXE will be created in your current directory i.e "c:\turboc".
You can run it by simply typing its name as given below.
C:\TURBOC>sample.exe Good Morning <press-enter-key>
C:\TURBOC>SAMPLE Good Morning <press-enter-key>
Here "sample" is the 'exe-file-name-or-command' and "Good Morning" is the arguments supplied to the exe-file-or-command called "sample" which is created by compiling the C program "sample.c".
Hope this will help you. Have a nice day!
|Jayant Jadhav said: (Feb 20, 2012)|
|argc which count number of word or characters separated by space and it holds int value. In this example three words are their including file name.Hence argc print 3.
argv this is argument vector array which holes all arguments in string format and store from starting index with 0.
|Vijay said: (Mar 30, 2012)|
|Can any one explain how actually memory allocation is done in command line argument.|
|Jogamohan Medak said: (Oct 20, 2012)|
%d argc=3 because (argv,argv,argv only three arguments argv)
|Abir Sen said: (Oct 25, 2013)|
argc = 3 because no of arguments that are passed is 3 in the program.
arv = ./a.out,
argv = Good,
argv = Morning.
|Padmapriya said: (Sep 14, 2014)|
|But I have a doubt guys. Usually the count value will start with 0, but how here started with 1. Is that the rule for argc. Please explain.|
|Naga Vikas said: (Mar 24, 2015)|
|Does this depends on the compilers? Because I get it as 4 Sample.
Anyone please tell me?
|Zara said: (Feb 15, 2016)|
|Sample Good Morning are three words, so argc will total words like sample = 1 good = 2 and morning = 3 that is total 3 counts and argv contains argv = sample, argv = good, and argv = morning.
So output will be at printf ("%d %s", argc, argv); 3 count at argc, and good at argv that is 3 Good.
|Prash... said: (Dec 8, 2016)|
|Garima said: (May 8, 2017)|
|Why it count? Please explain me.|
|Datts said: (Nov 11, 2018)|
|After a first value insertion count is automatically incremented i.e. count++.|
|Meera said: (Aug 2, 2020)|
|I am not understanding this, Please anyone help me.|
Post your comments here:
Email : (optional)
» Your comments will be displayed only after manual approval.