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
/* myprog.c */
#include<stdio.h>

int main(int argc, char *argv[])
{
    printf("%c", *++argv[1]);
    return 0;
}
r
f
m
y
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
12 comments Page 2 of 2.

Sudha said:   1 decade 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.

A$tro said:   1 decade 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.


Post your comments here:

Your comments will be displayed after verification.