Search
 
SCRIPT & CODE EXAMPLE
 

C

initialize array c


    // designated initialization --> it's a way to initialize elements of an array by it's index,
    // and set the value of the other elements to 0

    // ex 1
    int arr[5] = {[2] = 5, [3] = 10};
    for (int i = 0; i < 5; i++)
    {
        printf("%d ", arr[i]); // 0 0 5 10 0
    }
	
	// ex 2
	int arr[10] = {1, 7, [2] = 5, [3] = 10};
	for(int i = 0;i<10;i++){
		printf("%d ", arr[i]); // 1 7 5 10 0 0 0 0 0 0
    }
	// ex 3
	int arr[ ] = {2, [5] = 1}; // size is 6
    printf("%lu", sizeof(arr)); // 24 --> 6 * 4

Comment

c array initialization

int x[] = {1,2,3}; // x has type int[3] and holds 1,2,3
int y[5] = {1,2,3}; // y has type int[5] and holds 1,2,3,0,0
int z[3] = {0}; // z has type int[3] and holds all zeroes
Comment

PREVIOUS NEXT
Code Example
C :: c code to add two numbers 
C :: c substring 
C :: C scanf() to read a string 
C :: how to get input in 2d array in c 
C :: celsius to fahrenheit formula 
C :: plt legend top right outside 
C :: remove string from string c 
C :: char to int in c 
C :: how to reset all values of 2d vector to 0 
C :: c round float 
C :: server client tcp in C 
C :: print hello world in c 
C :: DrawText() raylib 
C :: binary search tree of strings in c 
C :: qtableview get selected row 
C :: Leap year using function in c 
C :: terraform fargate cpu 
C :: pyinstaller hidden import tensorflow not found 
C :: c check if character is upper case 
C :: c defined 
C :: Compile multiple C files 
C :: hash function in c 
C :: realloc in c 
C :: C #ifdef Directive 
C :: largest value in u64 
C :: how to do Employing defensive code in the UI to ensure that the current frame is the most top level window 
C :: error: argument 1 range [18446744071562067968, 18446744073709551615] exceeds maximum object size 9223372036854775807 [-werror=alloc-size-larger-than=] 
C :: abs() for floting point in C 
C :: how to input a para in c 
C :: Uri/beecrowd problem no - 1099 solution in C 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =