954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

clrscr is usually given after declaration of variables. why ?

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 !!

rocky2008
Newbie Poster
9 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

Read "C Program Structure" section from your text book. I am sure, you will get the answer.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

you can't put executable statements before variable declarations in C language.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

i couldn't find the answer. can u please help me if you know the answer.
Read "C Program Structure" section from your text book. I am sure, you will get the answer.

rocky2008
Newbie Poster
9 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

thanks for your response. but can u please tell me why executable statements cant be given before variable declaration ?
you can't put executable statements before variable declarations in C language.

rocky2008
Newbie Poster
9 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

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.

// includes go here
#include <stdio.h>
...
int main(int argc, char* argv[])
{
    // all variable declarations go here
    //
    // executable statements follow
    //
    {
         // new block, so more variables here
         // followed by executable statements
    } // end of block
} // end of main() function
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 
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)

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

oh!! then does this problem arise because of the problem in allocating the required amount of memory by the compiler ?

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)
rocky2008
Newbie Poster
9 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 
oh!! then does this problem arise because of the problem in allocating the required amount of memory by the compiler ?

Its not aproblem. The C language was designed like that some 35+ years ago (officially 1972).

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

hmmm... ok... thanks !!
Its not a problem. The C language was designed like that some 35+ years ago (officially 1972).

rocky2008
Newbie Poster
9 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

Here is the structure of c program:

C Program has three sections:


--------------------------Section 1--------------------
General declaration & File inclusion section
Note: In this section you may put header files and
declaration : variables, struct, user defined function etc.

------------------------Section 2------------------------
Entry Point main() function definition
Note: Further, every c function definition is falls into two sub-sections.
int main()
{
----------- Local declaration -------------
variables, struct, user defined function etc....

------------Statements-------------------
..
return 0;
}

--------------------Section 3 ----------------------
User defined function definition.


Lets look at this code:

/* general declaration & file inclusion */
#include <stdio.h>

void test(int n);  

/* Entry point - main() function */
int main()
 {
    /* declaration  & initilization*/
     int k=10;

    /* statements */
    test(k);

   return 0;
  }

void test(int n)
 {
     /* declaration */
      int p;
    
     /* statements */
     p=n*n;
     printf("\nSquare : %d",p);
}
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

>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)
Mixing declarations and executable statements is a feature that's been available since C99, and quite a few compilers support it.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You