Skip to main content

All Questions

Tagged with
0 votes
1 answer
55 views

Why I didnot get Multiple definition Error?

#include <stdio.h> #define MAX 5 static int data = 10; int increment(void *); int increment(void *ptr) { int *p = ptr; static int data =15; for (int loop=0; loop < MAX; loop++...
fw08's user avatar
  • 126
-1 votes
1 answer
90 views

Global file pointer in C

I'm having a problem with a global file pointer in C with Visual Studio 2022 in a solution involving a large number of files that are compiled and linked using the "Build" command. Based on ...
csharp's user avatar
  • 522
-2 votes
2 answers
69 views

Shell script for finding global variables

How would one write a shell script that finds all the global variables in a given C program? I don't need a long line like global_vars=$(grep -E '^[[:space:]]*[a-zA-Z_][a-zA-Z0-9_]*[[:space:]]+[a-zA-...
user24644517's user avatar
4 votes
2 answers
156 views

Should I use global variables in recursion

I created a function in C to find the shortest path out of a triangle maze using recursion. I use 2 global variables in the function, which I want to get rid of because I know that global variables ...
demon's user avatar
  • 59
1 vote
3 answers
414 views

Scope of a structure in C language

Could someone explain in simple terms what is meant by this? The scope of a structure begins at its appearance in a type specifier, and persists to the end of the translation unit (for declarations ...
alessio solari's user avatar
0 votes
1 answer
67 views

static variables not initialized in C [closed]

In a C program I have this code in a file. It wants to use a static global variable to control verbose output. But the variable is not what I assigned, so I started to play. static int _varA = 0; ...
Droidum's user avatar
  • 434
1 vote
1 answer
92 views

Storage of uninitialized global static variable in C programming

As I learn, uninitialized global static variable take memory space in bss. But while i am declaring a global static variable in my c program, the size of the bss is not increasing. I tried: #include&...
A coin has two sides's user avatar
1 vote
3 answers
109 views

Initializing global arrays after declaration in C

I need a global array whose size depends on the user. The problem is I don't know how to declare an array globally but initialize it later after getting a user input to know the size. I am not even ...
Randaniel's user avatar
-2 votes
4 answers
495 views

Static variable in global and local scope

I want to know what is the difference between declaring a static variable locally and globally, because in below example. If results do not impact, then why we have two scopes for static? #include <...
krupa n's user avatar
0 votes
1 answer
41 views

gcc complaining "multiple definition of 'funname' ", then how to declare a global character array? [duplicate]

I have a header error.h, and this is where I want to declare my global character array funname. My idea is to declare funname in error.h, and include this header in all of my *.c files. funname stores ...
Cinverse's user avatar
  • 128
2 votes
1 answer
72 views

C Pointer assignments - global

The following code: #include<stdio.h> #include<stdlib.h> char *msg = "Hello, World!"; char *p; p = msg; int main() { puts(msg); return EXIT_SUCCESS; } gives an error ...
Thushan's user avatar
  • 21
1 vote
2 answers
929 views

Why and where to use a global variable and a static global variable in C?

I have read about global and local variables and static keyword, but i dont know which is the difference between something like this: int x; //Global variable int main(){ //Code... } And this: ...
Cblue X's user avatar
  • 327
0 votes
0 answers
43 views

Why is the actual memory usage in task manager different from the theoretical memory usage for C?

#include <stdio.h> #include <unistd.h> typedef struct kk { char k[1000000]; } uuuu; uuuu k[1000]; int main() { sleep(100); return 0; } The theoretical memory usage for this program ...
Ryaaan's user avatar
  • 13
-2 votes
1 answer
107 views

Is it possible to pass a global char variable as a parameter in a function?

So I have a global variable called char words[10]. I would like to pass it as a parameter as in a function. This is the code I have so far and it does not compile obviously. I just do not know how ...
zeee's user avatar
  • 1
1 vote
0 answers
140 views

How to determine in Clang API if a reference is to a global?

Using the Clang Python API I am trying to figure out if a reference to a C identifier is to a global definition - i.e. the scope of the identifier is more than to just a single file or sub-part ...
Steve V's user avatar
  • 11

15 30 50 per page
1
2 3 4 5
16