C Programming - Command Line Arguments - Discussion
Discussion Forum : Command Line Arguments - Find Output of Program (Q.No. 9)
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
cmd> myprog friday tuesday sunday
/* myprog.c */
#include<stdio.h>
int main(int argc, char *argv[])
{
printf("%c", *++argv[1]);
return 0;
}
Discussion:
12 comments Page 1 of 2.
Vaishali said:
8 years ago
Is there any differences between **++argv and *++argv?
A$tro said:
9 years ago
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.
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.
Sudha said:
10 years ago
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.
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.
Dfds said:
1 decade ago
argv[1] means Friday.
When we increment pointer by one it will point to r.
When we increment pointer by one it will point to r.
Sunaina said:
1 decade ago
Whats the difference between *++argv and **+argv?
Sanjoy said:
1 decade ago
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".
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".
Ashutosh said:
1 decade ago
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.
KomPri said:
1 decade ago
Hi guys....
++argv=friday & ++argv[1]=r
so the output is correct
++argv=friday & ++argv[1]=r
so the output is correct
Raut said:
1 decade ago
@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
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
Pradeep said:
1 decade ago
Can,any one explain wat is difference between argc and argv?and wat operation it performs in program?with example....
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers