Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

what is wrong with this code i wrote?

+6 votes
asked Dec 27, 2018 by satyamthassu (180 points)
int count;
void p() {
    int count = 100;
    report();

}
int p2(){
  void  count = 200;
    report();
    
}
void report(){
    printf("%d",count);
    
}
int main()
{
    int count = 300;
    p();
    p2();
    report();

    return 0;
}

2 Answers

+1 vote
answered Dec 27, 2018 by Jasjit Singh Rayat
#include <stdio.h>
int count;
void report(){
    printf("%d",count);
    
}
void p() {
    count = 100;
    report();

}
int p2(){
    count = 200;
    report();
    
}

int main()
{
    count = 300;
    p();
    p2();
    report();

    return 0;
}

/// Hey there , first of all the sequence of functions declared and defined matters in C as it follows top to down approach. Secondly once declared int count with global scope you dont need to re delcare them again and again in each function . Also no variable can have Void Data type as you have done in function p2()
0 votes
answered Dec 28, 2018 by alfastatic (160 points)

As an alternative by Jasjit Singh Rayat: 

#include <stdio.h>

void report();  // i say in this line : I will create this function in the future TRUST ME!  :)

int count;


void p() {
    count = 100;
    report();

}
int p2(){
    count = 200;
    report();
    
}
void report(){
    printf("%d",count);
    
}
int main()
{
    count = 300;
    p();
    p2();
    report();

    return 0;
}

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...