IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C++ Programming C# Programming Java Programming
Microbiology Biochemistry Biotechnology Biochemical Engineering
Civil Engineering Mechanical Engineering Chemical Engineering Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

C Programming - Command Line Arguments - Discussion

@ : Home > C Programming > Command Line Arguments > Yes / No Questions - Discussion

Read more:

"Two things are infinite: the universe and human stupidity; and I'm not sure about the universe."
- Albert Einstein
2. 

If the different command line arguments are supplied at different times would the output of the following program change?

#include<stdio.h>

int main(int argc, char **argv)
{
    printf("%d\n", argv[argc]);
    return 0;
}

[A]. Yes[B]. No

Answer: Option D

Explanation:

No answer description available for this question.


Deepika said: (Fri, Oct 22, 2010 09:58:21 AM)    
 
Anyone please help me. How is it works?

Sundar said: (Fri, Oct 22, 2010 11:04:31 AM)    
 
@Deepika:

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[0] = 1st argument value
argv[1] = 2nd argument value
argv[2] = 3rd argument value.

But in the given program, it is mentioned like

argv[argc] it means that argv[3].

This array holds the values upto argv[2] only (argv[0] - argv[2]).

Therefore, argv[3] 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.

Note:

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!

Karthi said: (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)    
 
Sundar rocks.

Parag said: (Mon, Jul 11, 2011 06:10:13 AM)    
 
@Sundar

Nice ans. Thanks.

Arun said: (Wed, Aug 3, 2011 01:48:17 PM)    
 
Good explanation sundar keep going.

Meenu said: (Fri, Dec 16, 2011 10:40:33 AM)    
 
Thank you sundar.

Deepika said: (Tue, Feb 14, 2012 11:56:09 AM)    
 
Excellent Sundar.. :)

Neha said: (Wed, May 23, 2012 01:36:08 PM)    
 
Thank you sundar.

Adarsh said: (Sat, Jul 21, 2012 05:13:51 PM)    
 
Nice explanation.

@sundar.

Subhendu Bera said: (Wed, Aug 22, 2012 07:18:19 PM)    
 
According to the C standard 2011 section 5.1.2.2.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[3] 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.

Jessie said: (Tue, Sep 4, 2012 01:13:25 AM)    
 
Thank you sundar;keep it up

Ramakri said: (Tue, Dec 4, 2012 12:14:14 PM)    
 
Is ** argv is same as *argv[]?

usually we use,

int main(int argc, char *argv[]);

Write your comments here:
Name *:     Email:


© 2008-2013 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Contact us: info@indiabix.com     Follow us on twitter!