clrscr is usually given after declaration of variables. why ?

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2008
Posts: 9
Reputation: rocky2008 is an unknown quantity at this point 
Solved Threads: 0
rocky2008 rocky2008 is offline Offline
Newbie Poster

clrscr is usually given after declaration of variables. why ?

 
0
  #1
May 27th, 2009
clrscr() is usually given after the declaration of all variables. If it is given before the declaration(of variables), the compiler points out an error. Why is this due to ? Will there be any problem in allocating the required amount of memory if at all clrscr() is given before the declaration?

Kindly reply to this question !!

Thanks !!
Regards,
Rocky.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,721
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 501
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: clrscr is usually given after declaration of variables. why ?

 
0
  #2
May 27th, 2009
Read "C Program Structure" section from your text book. I am sure, you will get the answer.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,648
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1498
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: clrscr is usually given after declaration of variables. why ?

 
0
  #3
May 27th, 2009
you can't put executable statements before variable declarations in C language.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 9
Reputation: rocky2008 is an unknown quantity at this point 
Solved Threads: 0
rocky2008 rocky2008 is offline Offline
Newbie Poster

Re: clrscr is usually given after declaration of variables. why ?

 
0
  #4
May 27th, 2009
i couldn't find the answer. can u please help me if you know the answer.
Originally Posted by adatapost View Post
Read "C Program Structure" section from your text book. I am sure, you will get the answer.
Regards,
Rocky.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 9
Reputation: rocky2008 is an unknown quantity at this point 
Solved Threads: 0
rocky2008 rocky2008 is offline Offline
Newbie Poster

Re: clrscr is usually given after declaration of variables. why ?

 
0
  #5
May 27th, 2009
thanks for your response. but can u please tell me why executable statements cant be given before variable declaration ?
Originally Posted by Ancient Dragon View Post
you can't put executable statements before variable declarations in C language.
Regards,
Rocky.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,648
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1498
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: clrscr is usually given after declaration of variables. why ?

 
0
  #6
May 27th, 2009
If the answer is not in your text book then you need a different book! But I'm sure its in the book, you just need to study the sections about C language program structure.
  1. // includes go here
  2. #include <stdio.h>
  3. ...
  4. int main(int argc, char* argv[])
  5. {
  6. // all variable declarations go here
  7. //
  8. // executable statements follow
  9. //
  10. {
  11. // new block, so more variables here
  12. // followed by executable statements
  13. } // end of block
  14. } // end of main() function
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,648
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1498
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: clrscr is usually given after declaration of variables. why ?

 
0
  #7
May 27th, 2009
Originally Posted by rocky2008 View Post
thanks for your response. but can u please tell me why executable statements cant be given before variable declaration ?
Yes -- because the iso standards say so. I have read that this requirement is going to be relaxed in the next revision of the standards, but no compilers have implemented that yet (for obvious reasons)
Last edited by Ancient Dragon; May 27th, 2009 at 8:30 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 9
Reputation: rocky2008 is an unknown quantity at this point 
Solved Threads: 0
rocky2008 rocky2008 is offline Offline
Newbie Poster

Re: clrscr is usually given after declaration of variables. why ?

 
0
  #8
May 27th, 2009
oh!! then does this problem arise because of the problem in allocating the required amount of memory by the compiler ?

Originally Posted by Ancient Dragon View Post
Yes -- because the iso standards say so. I have read that this requirement is going to be relaxed in the next revision of the standards, but no compilers have implemented that yet (for obvious reasons)
Regards,
Rocky.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,648
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1498
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: clrscr is usually given after declaration of variables. why ?

 
0
  #9
May 27th, 2009
Originally Posted by rocky2008 View Post
oh!! then does this problem arise because of the problem in allocating the required amount of memory by the compiler ?
Its not a problem. The C language was designed like that some 35+ years ago (officially 1972).
Last edited by Ancient Dragon; May 27th, 2009 at 8:50 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 9
Reputation: rocky2008 is an unknown quantity at this point 
Solved Threads: 0
rocky2008 rocky2008 is offline Offline
Newbie Poster

Re: clrscr is usually given after declaration of variables. why ?

 
0
  #10
May 27th, 2009
hmmm... ok... thanks !!
Originally Posted by Ancient Dragon View Post
Its not a problem. The C language was designed like that some 35+ years ago (officially 1972).
Regards,
Rocky.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 646 | Replies: 11
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC