Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
#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 4:40am
v2

You are using all keywords starting with CAPS.

Add missing semicolon too.

Try:
C++
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*/
}
 
Share this answer
 
C and C++ are case sensitive: Void is not the same a void.
C++
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:
C++
#include <studio.h>
Should be
C++
#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:
C++
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:
C++
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.
C++
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.
 
Share this answer
 
C++
#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
C++
#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.
 
Share this answer
 
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