Help! I'm a Beginner

127 views
Skip to first unread message

Aparna Prasad

unread,
Oct 29, 2013, 1:01:13 PM10/29/13
to std-dis...@isocpp.org
#include<iostream.h>
#include<stdlib.h>
int main()
{  int rnum,i;
   for(i=0;i<5;++i)
    cout<<(rnum=rand())<<endl;
   return 0;
}






Q: How does rnum get its value since no number is taken as input nor it is declared?


P.S

This is my program 
i have copied this from my book(beginning random numbers)

David Rodríguez Ibeas

unread,
Oct 29, 2013, 1:04:13 PM10/29/13
to std-dis...@isocpp.org
This is not the correct forum for that question. Consider going to a Q&A programmer's web page (Stack Overflow is the first example that comes to mind).

David


--
 
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-discussion/.

Václav Zeman

unread,
Oct 30, 2013, 5:47:20 AM10/30/13
to std-dis...@isocpp.org, Václav Zeman
Dne úterý, 29. října 2013 18:01:13 UTC+1 Aparna Prasad napsal(a):
#include<iostream.h>
#include<stdlib.h>
int main()
{  int rnum,i;
   for(i=0;i<5;++i)
    cout<<(rnum=rand())<<endl;
   return 0;
}

[...]

This is my program 
i have copied this from my book(beginning random numbers)

Your book is ancient. Burn it with fire and get some from this list: http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list
 

Daryle Walker

unread,
Nov 4, 2013, 1:29:10 PM11/4/13
to std-dis...@isocpp.org
As others have said, this forum discusses the rules of C++, not general usage.


On Tuesday, October 29, 2013 1:01:13 PM UTC-4, Aparna Prasad wrote:
#include<iostream.h>
#include<stdlib.h>
int main()
{  int rnum,i;
   for(i=0;i<5;++i)
    cout<<(rnum=rand())<<endl;
   return 0;
}






Q: How does rnum get its value since no number is taken as input nor it is declared?

To actually answer your question: unlike other languages, assignment is an expression instead of just a statement. rnum is assigned the return value of the latest rand() call, then rnum is passed to the operator << call with cout. rand() is declared in the <stdlib.h> header.
 
P.S

This is my program 
i have copied this from my book(beginning random numbers)

If the book is from the era that <iostream.h> was around, it's way too old.

Daryle W.

Reply all
Reply to author
Forward
0 new messages