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 to initialize an array in Java?
- Initialize part of an array in java
- How do I determine the size of my array in C?
- char *array and char array[]
- 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?
- Error “initializer element is not constant” when trying to initialize variable with const
- How do you make an array of structs in C?
- Getting “conflicting types for function” in C, why?
- Double array initialization in Java
- Is there a function to copy an array in C/C++?
- How do I create an array of strings in C?
- Return char[]/string from a function [duplicate]
- Why am I getting “array initializer must be an initializer list or string literal”?
- What does ** do in C language?
- How to initialize a struct in accordance with C programming language standards
- Using Dynamic Memory allocation for arrays
- How do I create an array of strings in C?
- How to make an array with a dynamic size? General usage of dynamic arrays (maybe pointers too)?
- How can I use an array of function pointers?
- Finding the length of a Character Array in C
- Return char[]/string from a function
- How to print a char array in C through printf?
- How to clear all the elements of array in C?
- Zero an array in C code
- Passing an array by reference in C?
- Excess elements in char array initializer error
- waitpid, wnohang, wuntraced. How do I use these
- How to do scanf for single char in C
- Sign extend a nine-bit number in C
- Warning: assignment from incompatible pointer type
- Break statement not within loop or switch in C
- How to create an array of strings in C?
- C++ array assign error: invalid array assignment
- Cache Simulator in C
- C: error: expected ‘)’ before ‘;’ token
- Where is the C auto keyword used?
- make: Nothing to be done for `all’
- Initialization from incompatible pointer type warning when assigning to a pointer
- I’m getting “Invalid Initializer”, what am I doing wrong?
- 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 - expected expression before ‘{‘ token
- Setting std=c99 flag in GCC
- C Vector/ArrayList/LinkedList
- Bind failed: Address already in use
- Warning/error “function declaration isn’t a prototype”
- What is the difference between %f and %lf in C?
- warning: initializer element is not computable at load time
- What is stdin in C language?
- How to prevent multiple definitions in C?
- How to pass 2D array (matrix) in a function in C?
- error: ‘for’ loop initial declarations are only allowed in C99 mode [duplicate]
- How can you print multiple variables inside a string using printf?
- 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
- how to initialize an empty integer array in c++
- Iterate through a C array
- What is time(NULL) in C?
- What is the default initialization of an array in Java?
- Use of cudamalloc(). Why the double pointer?
- C dynamically growing array
- Why should we check WIFEXITED after wait in order to kill child processes in Linux system call?
- How to compile makefile using MinGW?
- Mapping a numeric range onto another
- Why are hexadecimal numbers prefixed with 0x?
- Portable way to check if directory exists [Windows/Linux, C]
- C++ – Too Many Initializers for Arrays
- OpenGL — GL_LINE_LOOP —
- too many arguments for format [-Wformat-extra-args]
- How to use EOF to run through a text file in C?
- Incorrect checksum for freed object on malloc