Click here to Skip to main content
14,696,627 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#include <studio.h>
Void f(void);
Int main(void)
{
Int i;
for (i=0;  i<10; i++) f( );
return 0;
}
Void f(void)
{
int j=10;
printf("%d " , j)
j++;
/* This line has no lasting effect*/
}


What I have tried:

I am getting error declaration incorrectly
It is a program of local variable
Posted
Updated 27-Sep-20 5:40am
v2

You are using all keywords starting with CAPS.

Add missing semicolon too.

Try:
void f(void);
int main(void)
{
    int i;
    for (i=0; i<10; i++) f( );
    return 0;
}

void f(void)
{
    int j=10;
    printf("%d " , j);
    j++;
    /* This line has no lasting effect*/
}
   
C and C++ are case sensitive: Void is not the same a void.
Void f(void);
The same thing applies to Int and all other keywords, functions, properties, and so forth.
It also requires the header file names to be accurate:
#include <studio.h>
Should be
#include <stdio.h>


It's a very good idea to also do three other things with your code:
1) Indent it!
This is hard to read at best:
include <studio.h>
Void f(void);
Int main(void)
{
Int i;
for (i=0;  i<10; i++) f( );
return 0;
}
Void f(void)
{
int j=10;
printf("%d " , j)
j++;
/* This line has no lasting effect*/
}
Indent it, and it's more obvious:
include <studio.h>
Void f(void);
Int main(void)
    {
    Int i;
    for (i=0;  i<10; i++) f( );
    return 0;
    }
Void f(void)
    {
    int j=10;
    printf("%d " , j)
    j++;
    /* This line has no lasting effect*/
    }

2) Particularly when you are getting started, always use curly brackets even when tehy aren't strictly needed.
int main(void)
    {
    int i;
    for (i = 0; i < 10; i++) 
        {
        f( );
        }
    return 0;
    }
That way, when you change your code, you are a lot, lot more likely to get the new lines of code inside your loop instead of after it!

3) Don't use single character names: they may be easier to type, but they are also a lot easier to get wrong, and much harder to work out what is going on. And when you come back to code after a month on something else, readability is very, very important! Having meaningful names for variables and functions helps your code be self documenting, and that makes it a lot easier to work with.
   
#include <studio.h>
Void f(void);
Int main(void)
{
Int i;
for (i=0;  i<10; i++)
 f( );
return 0;
}
Void f(void)
{
int j=10; /* Note that this line resets j every time you call s, this is local variable*/
printf("%d " , j);
j++; /* 1) This line has no lasting effect*/
/* 2) because effect start to apply here*/
} /* 3) and ends here*/

Try
#include <studio.h>
Void f(void);
Int main(void)
{
Int i;
for (i=0;  i<10; i++) f( );
return 0;
}
Void f(void)
{
int j=10;
j++; /* Move the line here to see its effect on print */
printf("%d " , j);
}

You may want to study variables scope.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900