Re: Can u tell me the explanation reg this problem
- From: Eric Sosman <Eric.Sosman@xxxxxxx>
- Date: Mon, 05 Jun 2006 14:31:20 -0400
Sree wrote On 06/05/06 13:43,:
If the program (myprog) is run from the command line as myprog 1 2 3 ,
What would be the output?
main(int argc, char *argv[])
{
int i;
for(i=0;i<argc;i++)
printf("%s",argv[i]);
}
On some systems, the output would be
myprog123
However, there are some nasty little errors in the program
that might cause other things to happen:
- It calls printf() without a function prototype visible.
Add `#include <stdio.h>' at the beginning.
- It does not end its output with a newline character.
On some systems this will cause the interactive prompt
to appear right after the output
myprog123tardis>
On other systems, the output might not appear at all.
- It fails to return an `int' value from the main()
function to indicate whether the program succeeded
or failed. On some systems, this may produce an
output like
myprog123
%RMS-F-BADFILE, file structure is corrupt
Explain a lil bit abt these command line arguments and how they are
actually read
"How" the command-line arguments are parsed, prepared,
and handed to the program depends on the system that reads
the command line. Different systems do it differently, and
may make various modifications of their own, replacing the
characters you type with others. For example, some Unix
systems will treat `myprog ~' as if you had actually typed
`myprog /home/sree'. Details of this kind are not part of
the C language, and should be taken up on a forum devoted
to the system you are using.
Eventually the program's main() function receives some
values that are somehow derived from the command line and/or
other parts of the environment. These are represented as a
sequence of strings, and the first argc elements of the argv[]
array point to the strings' initial characters. The first
string (if there are any strings; argc can be zero) is some
kind of representation of the program name, but just what it
looks like is once again up to the host system: it might be
"myprog" or "myprog.exe" or "SYS$DISK:[HOME.SREE]MYPROG.EXE;3"
or something even less understandable. On most systems the
remaining strings will be "1", "2", and "3", although the C
language cannot guarantee exactly what happens before main()
is called. Finally, it will always be true that argv[argc]
is NULL, that is, that the last "real" string pointer is
followed by a NULL pointer.
What would be the output of the following program?
main()
{
char near * near *ptr1;
char near * far *ptr2;
char near * huge *ptr3;
printf("%d %d %d",sizeof(ptr1),sizeof(ptr2),sizeof(ptr3));
}
I don't know; it isn't C.
Plzz also explain how???
Can u suggest any good books which i can get online for referring such
questions
I don't know of any (that doesn't mean none exist, just
that I don't know of them). "The C Programming Language"
(second edition) by Kernighan & Ritchie is a highly recommended
hard-copy book.
--
Eric.Sosman@xxxxxxx
.
- Follow-Ups:
- Re: Can u tell me the explanation reg this problem
- From: spibou
- Re: Can u tell me the explanation reg this problem
- References:
- Prev by Date: Re: Can u tell me the explanation reg this problem
- Next by Date: Re: Arithmetic problem
- Previous by thread: Re: Can u tell me the explanation reg this problem
- Next by thread: Re: Can u tell me the explanation reg this problem
- Index(es):
Relevant Pages
|
|