Global variables and static variables are automatically initialized to zero. If you have simply
char ZEROARRAY[1024];
at global scope it will be all zeros at runtime. But actually there is a shorthand syntax if you had a local array. If an array is partially initialized, elements that are not initialized receive the value 0 of the appropriate type. You could write:
char ZEROARRAY[1024] = {0};
The compiler would fill the unwritten entries with zeros. Alternatively you could use memset
to initialize the array at program startup:
memset(ZEROARRAY, 0, 1024);
That would be useful if you had changed it and wanted to reset it back to all zeros
Related Posts:
- Initializing array of structures
- Initializing 2D char array in C
- “error: assignment to expression with array type error” when I assign a struct field (C)
- How to properly malloc for array of struct in C
- Convert char array to a int number in C
- Returning an array using C
- How to copy a char array in C?
- C subscripted value is neither array nor pointer nor vector when assigning an array element value
- struct has no member named
- How to empty a char array?
- What is the difference between array and enum in C ?
- Can I create an Array of Char pointers in C?
- Excess elements of scalar initializer for pointer to array of ints
- C char array initialization
- How to allocate array of pointers for strings by malloc in C?
- typedef fixed length array
- Constructor for structs in C
- C: warning: excess elements in array initializer; near initialization for ‘xxx’ ; expects ‘char *’, but has type ‘int’
- Pointer to 2D arrays in C
- How do I check if a string contains a certain character?
- How do I determine the size of my array in C?
- How do I create an array of strings in C?
- “Expected expression before ‘ { ‘ token”
- C pointers and arrays: [Warning] assignment makes pointer from integer without a cast
- How to print the array?
- Getting “conflicting types for function” in C, why?
- Getting “conflicting types for function” in C, why?
- Return char[]/string from a function [duplicate]
- Why am I getting “array initializer must be an initializer list or string literal”?
- How to make an array with a dynamic size? General usage of dynamic arrays (maybe pointers too)?
- How to print a char array in C through printf?
- How to clear all the elements of array in C?
- Warning: assignment from incompatible pointer type
- C: error: expected ‘)’ before ‘;’ token
- make: Nothing to be done for `all’
- Data argument not used by format strings in C
- execv vs execvp, why just one of them require the exact file’s path?
- difference between
and - Setting std=c99 flag in GCC
- warning: initializer element is not computable at load time
- error: ‘for’ loop initial declarations are only allowed in C99 mode [duplicate]
- c – warning: implicit declaration of function ‘printf’
- Flushing buffers in C
- What are 0x01 and 0x80 representative of in C bitwise operations?
- Convert char array to string use C
- How to make parent wait for all child processes to finish?
- Undefined Reference issues using Semaphores
- What is time(NULL) in C?
- What is the default initialization of an array in Java?
- C++ – Too Many Initializers for Arrays
- OpenGL — GL_LINE_LOOP —
- How to use EOF to run through a text file in C?
- Incorrect checksum for freed object on malloc
- Valgrind complains with “Invalid write of size 8”
- Expression must be a pointer to a complete object type using simple pointer arithmetic
- What does “request for member ‘*******’ in something not a structure or union” mean?
- Segmentation fault (core dumped) due to fgets – I think
- What does “request for member ‘*******’ in something not a structure or union” mean?
- Unknown ending signal when using debugger gdb
- Valgrind: invalid read of size 4 -> sigsegv, works fine without valgrind and in visual studio
- Is there a good Valgrind substitute for Windows?
- Difference between sizeof(char) and sizeof(char *)
- Difference between “move” and “li” in MIPS assembly language
- C# syntax to initialize custom class/objects through constructor params in array?
- Undefined reference to main – collect2: ld returned 1 exit status
- How can one see content of stack with GDB?
- What does the term “empty loop” refer to exactly in C and C++?
- What integer hash function are good that accepts an integer hash key?
- Proper way to empty a C-String
- malloc(): memory corruption
- How do you allow spaces to be entered using scanf?
- X86 assembly – Handling the IDIV instruction
- Pause screen at program completion in C
- Difference between fgets and fscanf?
- What is the difference between %g and %f in C?
- How can I find the number of elements in an array?
- Array type char[] is not assignable
- Structure padding and packing
- Lua – Number to string behaviour
- Parameter name omitted error?
- Reading in double values with scanf in c
- Dynamic vs static array in c
- Realloc Invalid Pointer in C
- The difference between char * and char[] [duplicate]
- What tools are there for functional programming in C?
- “-bash: gcc: command not found” using cygwin when compiling c?
- In C, what exactly happens when you pass a NULL pointer to strcmp()?
- What are the differences between if, else, and else if?
- strtok segmentation fault
- Invalid write of size 1
- How to solve static declaration follows non-static declaration in GCC C code?
- realloc(): invalid next size when reallocating to make space for strcat on char *
- C Error: declaration shadows a local variable — Won’t let me repeatedly replace the value of my float variable
- MIPS to C Translation
- Pointer to a string in C?
- gdb: No symbol “i” in current context
- Cross Platform C library for GUI Apps?
- Pre increment vs Post increment in array
- how to stop a loop arduino
- How to normalize a mantissa