agrc - It is an integer value contains the number of arguments passed to main function through command line.
Lets assume argc = 3.
The 3 arguments will be stored in the two dimensional array argv as given below.
argv = 1st argument value
argv = 2nd argument value
argv = 3rd argument value.
But in the given program, it is mentioned like
argv[argc] it means that argv.
This array holds the values upto argv only (argv - argv).
Therefore, argv may be contain null value or garbage value. While converting this value as integer (because in printf statement "%d" specified), it will give 0 as output.
Therefore, the program's output will NOT change due to the number of arguments passed.
If you use %s instead of %d in the printf statement, it may print (null) or any garbage value depends upon the platform. There is a chance for abnormal program termination too.
Hope this will help you. Have a nice day!
(Tue, Mar 1, 2011 01:40:45 PM)
Thank you somuch sundar. Its clear now.
Cool Buddy said:
(Fri, Mar 18, 2011 09:02:52 AM)
(Mon, Jul 11, 2011 06:10:13 AM)
Nice ans. Thanks.
(Wed, Aug 3, 2011 01:48:17 PM)
Good explanation sundar keep going.
(Fri, Dec 16, 2011 10:40:33 AM)
Thank you sundar.
(Tue, Feb 14, 2012 11:56:09 AM)
Excellent Sundar.. :)
(Wed, May 23, 2012 01:36:08 PM)
Thank you sundar.
(Sat, Jul 21, 2012 05:13:51 PM)
Subhendu Bera said:
(Wed, Aug 22, 2012 07:18:19 PM)
According to the C standard 2011 section 126.96.36.199.1 paragraph "argv[argc] shall be a null pointer." If it is printed using %d then it will print 0.
@sundar your statement "Therefore, argv may(**) be contain null value or garbage value(**)....." is wrong it will only contain null value. There is no scope of garbage and it is irrespective of compiler. If it "may be" null or gurbage then output would vary with every execution.