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:

"The secret to creativity is knowing how to hide your sources."
- Albert Einstein
2. 

What will be the output of the program (myprog.c) given below if it is executed from the command line?
cmd> myprog one two three

/* myprog.c */
#include<stdio.h>
#include<stdlib.h>

int main(int argc, char **argv)
{
    printf("%s\n", *++argv);
    return 0;
}

[A]. myprog[B]. one
[C]. two[D]. three

Answer: Option C

Explanation:

No answer description available for this question.


Hariom said: (Thu, Oct 21, 2010 03:50:38 AM)    
 
I think

argv[0]=myprog

++argv means argv[1]

thats why argv[1] = one

because of print string answer is one.

Jyotiranjan said: (Mon, Feb 21, 2011 12:53:01 PM)    
 
Execution start from right argv could not increased. Compiler will take the value first then increment. As first value was one.

So answer is one.

Vidi said: (Tue, Jun 14, 2011 02:52:03 AM)    
 
Can anyone elaborate on : char **argv[] used.

Ankur said: (Fri, Jul 1, 2011 06:53:59 AM)    
 
Can someone explain this output in detail ?

Sholvi.. said: (Sun, Sep 25, 2011 02:49:49 PM)    
 
I think here ...

argv[] means *argv and *argv[]=**argv
argv[0] or *argv contains address of string "myprog"
*argv[0]="myprog"

When we increament *argv it tends to next value stored as:
*argv[1]="one"
and as we can see in printf()=>"%s" is used so it will print the value of argv[1]
and we will get the ans:

Output: one

Rathika.B said: (Mon, Jan 16, 2012 08:07:47 PM)    
 
All mention only about argv. Then what about argc? what it can do here? & in function definition must match the parameters passing in command prompt. But we directly declare the strings here as one two three then how it accept?

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!