C Programming - Command Line Arguments - Discussion

9. 

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

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

int main(int argc, char *argv[])
{
    printf("%c", *++argv[1]);
    return 0;
}

[A]. r
[B]. f
[C]. m
[D]. y

Answer: Option A

Explanation:

No answer description available for this question.

Vishal Kumbhar said: (Feb 9, 2011)  
Guys,

argv[1] means "friay"

++arv[1] means "r"

it prints "r".
ok

Sunitha said: (Sep 25, 2011)  
argc converts first string datatype to integer hence the string myprog converted to integer and argc reads no of arguments that passed assigneed that values to argv hence pointer points to to string friday's first character and its get incremented and points to r.

Pradeep said: (Nov 10, 2011)  
Can,any one explain wat is difference between argc and argv?and wat operation it performs in program?with example....

Raut said: (Jan 20, 2012)  
@pradeep

int main(int argc,char *argv[])
here argc is total no argument you have passed through
command line argument and argv is an array of pointers which hold all pointers to the arguments which you have passed.
for ex my prog.c is a source file. after compilation you got myprog.exe file(lets say if you dont use other file name then you will get ./a.out file by default).
now we type myprog.exe apple orange
then argc=3
argv[0]=myprog.exe
argv[1]=apple
argv[2]=orange.

regards

Kompri said: (Aug 17, 2012)  
Hi guys....

++argv=friday & ++argv[1]=r
so the output is correct

Ashutosh said: (Oct 12, 2013)  
argv[1] is the base address of friday. And on incrementing the base address by will point to r because arg[] is a character pointer.

Sanjoy said: (Jan 28, 2014)  
argv[0] means " myprog ".

argv[1] indicates "Friday".

++argv[1] means = "riday".

It just point to the next character of f .
Here %c is given so only one character "r".

Will print if there were %s then "riday".
Would print,

printf("%c", *++argv[1]);

It prints "r".

Sunaina said: (Jan 29, 2014)  
Whats the difference between *++argv and **+argv?

Dfds said: (Mar 10, 2014)  
argv[1] means Friday.

When we increment pointer by one it will point to r.

Sudha said: (Mar 25, 2015)  
Friends.

The array has a continue memory allocation also. The array index start with zero is going on.

So the Friday store in array memory just like that start with zero.

So f contain a a[0]=f; a[1]=r; a[2]=i, a[_]=y; so the print "r";

Friends please justify the answer.

A$Tro said: (Aug 19, 2015)  
This program will print an output on both environment Linux/windows-and I think we can define an array size using either variable/macros/const.

As I've tried to define the max as shown:

int max =20;
C Const int max=20; ------------- and it works on both cases.

So may be the error depends on the standard ANSCI CS99 etc.

Vaishali said: (Aug 5, 2016)  
Is there any differences between **++argv and *++argv?

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.