cLanguage)Ask global variables.

Asked 1 years ago, Updated 1 years ago, 85 views

void set(int h, int m);

int h,m,;

int main(void)
{

    set(h,m);
    printf("%d%d", h,m);


}

void set(int h, int m)
{

    printf ("Enter the first hour (24 hours): ");
    scanf("%d%d", &h, &m);   
}

I'd like to initialize the global variables h and m as a set function, but it's only within the function and comes out as the initialization value, so what should I do? Instead of declaring void set(void), I would like to declare it as void set(int, intm).

c global-variable

2022-09-21 11:40

1 Answers

Just

void set()
{
    printf ("Enter the first hour (24 hours): ");
    scanf("%d %d",&h,&m);
}

This is how Hashim...

If you receive h and m as parameters like the questioner, the local variables h and m take precedence over the global variables h and m, so you cannot modify the variable you want.


2022-09-21 11:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.