Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Can u tell me the explanation reg this problem

Reply
Thread Tools

Can u tell me the explanation reg this problem

 
 
Sree
Guest
Posts: n/a
 
      06-05-2006
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]);
}


Explain a lil bit abt these command line arguments and how they are
actually read


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));
}


Plzz also explain how???




Can u suggest any good books which i can get online for referring such
questions

 
Reply With Quote
 
 
 
 
Andrew Poelstra
Guest
Posts: n/a
 
      06-05-2006
On 2006-06-05, Sree <(E-Mail Removed)> wrote:
> If the program (myprog) is run from the command line as myprog 1 2 3 ,
> What would be the output?

I imagine that the answer would be right in front of you. Unless you
are unclear on the concept of 'output'.

> main(int argc, char *argv[])

int main (int argc, char *argv)

> {
> int i;
> for(i=0;i<argc;i++)
> printf("%s",argv[i]);

return 0;
> }
>
> Explain a lil bit abt these command line arguments and how they are
> actually read
>

'lil' and 'abt' are not words.

>
> What would be the output of the following program?

Try it and see.

> main()

int main (void)
> {
> char near * near *ptr1;
> char near * far *ptr2;
> char near * huge *ptr3;
> printf("%d %d %d",sizeof(ptr1),sizeof(ptr2),sizeof(ptr3));

return 0;
> }

near, far, and huge aren't C keywords. You should get syntax errors.
>
>
> Plzz also explain how???
>
> Can u suggest any good books which i can get online for referring such
> questions
>

'Plzz', 'u', and lowercase 'i' are not words. You also used too many
question marks. One is enough.

--
Andrew Poelstra < http://www.wpsoftware.net/blog >
To email me, use "apoelstra" at the above address.
If we would just let the poachers into the zoo, we'd
have less squashed people and more fancy pianos!
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      06-05-2006


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.

--
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      06-05-2006
Andrew Poelstra <(E-Mail Removed)> writes:
> On 2006-06-05, Sree <(E-Mail Removed)> wrote:
>> If the program (myprog) is run from the command line as myprog 1 2 3 ,
>> What would be the output?

> I imagine that the answer would be right in front of you. Unless you
> are unclear on the concept of 'output'.
>
>> main(int argc, char *argv[])

> int main (int argc, char *argv)


I think you mean
int main(int argc, char *argv[])
or possibly the equivalent
int main(int argc, char **argv)

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
Andrew Poelstra
Guest
Posts: n/a
 
      06-05-2006
On 2006-06-05, Keith Thompson <(E-Mail Removed)> wrote:
> Andrew Poelstra <(E-Mail Removed)> writes:
>> On 2006-06-05, Sree <(E-Mail Removed)> wrote:
>>> If the program (myprog) is run from the command line as myprog 1 2 3 ,
>>> What would be the output?

>> I imagine that the answer would be right in front of you. Unless you
>> are unclear on the concept of 'output'.
>>
>>> main(int argc, char *argv[])

>> int main (int argc, char *argv)

>
> I think you mean
> int main(int argc, char *argv[])
> or possibly the equivalent
> int main(int argc, char **argv)
>


Yes, thank you. The second * was lost in my slow SSH
connection.

--
Andrew Poelstra < http://www.wpsoftware.net/blog >
To email me, use "apoelstra" at the above address.
If we would just let the poachers into the zoo, we'd
have less squashed people and more fancy pianos!
 
Reply With Quote
 
spibou@gmail.com
Guest
Posts: n/a
 
      06-05-2006

Eric Sosman wrote:

> The first
> string (if there are any strings; argc can be zero) is some
> kind of representation of the program name...


I was under the impression that the programme name will always be
passed as an argument so argc will be at least 1. Or is that just a
Unix
thing ?

 
Reply With Quote
 
Ico
Guest
Posts: n/a
 
      06-05-2006
Sree <(E-Mail Removed)> wrote:
> 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]);
> }
>
>
> Explain a lil bit abt these command line arguments and how they are
> actually read
>
>
> 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));
> }
>
>
> Plzz also explain how???
>
>
>
>
> Can u suggest any good books which i can get online for referring such
> questions


K&R would give you all the answers you need. Another good investement
would be a book about the English language. You are used to fact that
your compiler complains if you use wrong syntax or wrong identifiers in
your program code, so you take care to write proper C. Is it that much
work to do a little bit of work to write proper English, without all the
abbreviations like u, plzzz, abt and lil ? These make you look childish,
and will not help you getting useful answers to your questions.

--
:wq
^X^Cy^K^X^C^C^C^C
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      06-05-2006


(E-Mail Removed) wrote On 06/05/06 16:17,:
> Eric Sosman wrote:
>
>
>> The first
>>string (if there are any strings; argc can be zero) is some
>>kind of representation of the program name...

>
>
> I was under the impression that the programme name will always be
> passed as an argument so argc will be at least 1. Or is that just a
> Unix
> thing ?


In section 5.1.2.2.1 paragraph 2, the C Standard says
"the value of argc shall be nonnegative" (it doesn't say
"positive"), and it twice uses the phrase "if the value of
argc is greater than zero" in descriptions of the argv[]
values. The wording seems to imply the possibility that
argc might be zero in some environment that doesn't support
notions like "command line" or "program name."

The same paragraph says that if argv[0] is non-NULL it
shall point to a string that "represents the program name,"
but does not describe the form of the representation. It
also explicitly recognizes that no name might be available
even if other command-line arguments are present; in this
case, argv[0] points to an empty string "".

Other Standards that build atop the C Standard may
impose additional requirements, but I don't think I've run
across any that guarantee argv[0] will be "the" program
name. In the POSIX world, for example, argv[0] is whatever
was provided to the exec*() system call that launched the
program in the first place; this is only "conventionally"
the program name, and the convention is not enforced. (In
a few places, it is deliberately violated.)

Even when argv[0] is a program name, it doesn't follow
that you can use it to launch another copy of the program
via the system() function (or a system-specific facility).
The program "name" might turn out to be a shell alias that
isn't exported to sub-shells -- more generally, the "name"
may be "the" name only in a context that isn't available
inside the program.

The value of argv[0] is usually something that's useful
for "decorating" errors and status messages, but not "solid"
enough to rest your program's operation upon. A widely-used
hack installs a single executable file with several names,
where the program inspects argv[0] to decide how it should
behave; this sort of thing may have been justifiable in the
days of small disks and static libraries, but is hard to
defend today. Some programmers use argv[0] to find "the"
program's installation directory where configuration files
and suchlike are stored; this isn't terribly reliable (and
can be downright UNreliable on multi-user systems).

--
(E-Mail Removed)

 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      06-05-2006
Sree wrote:
>
> 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]);
> }
>
> Explain a lil bit abt these command line arguments and how they are
> actually read


lil is usually a girls nickname. Abt is meaningless to me.

>
> 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));
> }


It wouldn't compile on a C compiler. It would emit something like
"syntax error". Even the printf, taken in isolation, would cause
undefined behaviour.

>
> Plzz also explain how???
>
> Can u suggest any good books which i can get online for referring such
> questions


Who is 'plzz'? Who is 'u'?

--
"Our enemies are innovative and resourceful, and so are we.
They never stop thinking about new ways to harm our country
and our people, and neither do we." -- G. W. Bush.
"The people can always be brought to the bidding of the
leaders. All you have to do is tell them they are being
attacked and denounce the pacifists for lack of patriotism
and exposing the country to danger. It works the same way
in any country." --Hermann Goering.


 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      06-05-2006
Ico <(E-Mail Removed)> writes:
> Sree <(E-Mail Removed)> wrote:

[...]
>> main()
>> {
>> char near * near *ptr1;
>> char near * far *ptr2;
>> char near * huge *ptr3;
>> printf("%d %d %d",sizeof(ptr1),sizeof(ptr2),sizeof(ptr3));
>> }

[...]
>> Can u suggest any good books which i can get online for referring such
>> questions

>
> K&R would give you all the answers you need.

[...]

K&R won't tell you anything about "near" and "far" pointers.

But that probably *is* all you need to know about "near" and "far"
pointers (unless you're actually programming for any of the few
remaining systems that still use them). They've never been standard,
and they're largely obsolete.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Some people tell that at present, most web hosting servers supportall kinds of programming language, some people tell me that many web hostingserver don't support Java, What is the truth? Erwin Moller Java 3 05-07-2008 05:09 PM
CAN any one tell it whats the code tell it yogesh C++ 1 03-14-2007 01:12 PM
Can u tell me the explanation reg this problem Sree C Programming 6 06-07-2006 03:33 AM
Windows Reg Pro vs Tweak now Reg Cleaner vs Registry fix, vs RegCleaner jl Computer Support 3 05-31-2005 12:53 AM
Script to Tell Tell Time then Limit by it? Mike A Javascript 17 11-19-2003 02:16 PM



Advertisments