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 Java Programming
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 > Find Output of Program - Discussion

Read more:

"In the middle of difficulty lies opportunity."
- Albert Einstein
18. 

What will be the output of the program (sample.c) given below if it is executed from the command line?
cmd> sample friday tuesday sunday

/* sample.c */
#include<stdio.h>

int main(int sizeofargv, char *argv[])
{
    while(sizeofargv)
        printf("%s", argv[--sizeofargv]);
    return 0;
}

[A]. sample friday tuesday sunday
[B]. sample friday tuesday
[C]. sunday tuesday friday sample
[D]. sunday tuesday friday

Answer: Option E

Explanation:

No answer description available for this question.


Balaji M said: (Fri, Dec 10, 2010 05:36:46 AM)    
 
I need explanation regarding your answer.

Pandi said: (Fri, Dec 17, 2010 08:46:17 AM)    
 
pls tell me about the detailed answer

Arvind said: (Tue, Feb 22, 2011 02:13:28 AM)    
 
The first parameter inside main() contains the number of command line arguments. so sizeofargv = 4.
The second parameter inside main() contains the command line arguments as an array of string. so
*argv[3] = sunday
*argv[2] = tuesday
*argv[1] = friday
*argv[0] = sample

Mani said: (Thu, Jun 23, 2011 12:47:53 AM)    
 
Thanks Arvind.

Prudhvi said: (Wed, Jul 20, 2011 07:33:42 PM)    
 
Here sample is name of the program how can be it be an argument ?

Yogesh said: (Sat, Aug 27, 2011 01:16:34 PM)    
 
The first parameter inside main(....)determines the number of cmd line arguments i.e sizeofargv=4.
and second parameter stores the actual parameters in array
i.e.
argv[3] = sunday
argv[2] = tuesday
argv[1] = friday
argv[0] = sample

while loop executed four times. It breaks when value of sizeofargv becomes -1.
Output:
in first execution: argv[3]=sunday
in second execution: argv[2] =tuesday
in third execution: argv[1]=friday
in fourth execution argv[0]=sample
now value of sizeofargv becomes -1 and loop breaks.

Ferissa said: (Mon, Sep 12, 2011 05:40:08 PM)    
 
Hi pruthvi this is ferissa, I think there is no error when the program name matches with the argument.

Narmada said: (Wed, Nov 2, 2011 09:57:10 PM)    
 
Pruthvi in c for command line arguments the program name will be consider as first argument as argv[0]. So sample will be stored in argv[0].

Prakash said: (Sat, Dec 10, 2011 01:55:39 PM)    
 
Great yogesh.....

Write your comments here:
Name *:     Email:


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

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