array
title: "courses/c-course - array.md"
- **fileName**: array
- **Created on**: 2024-06-08 09:18:40
array is a collocation for the same data types
char username[] = "yossef";
int ages[] = { 1, 2, 4 ,56 ,6};
you can get the size of an array by sizeof
keyworad for example sizeof(username);
can adding one and two and three domination for array by
int nubmers[] = { 29, 22 ,292}
// two 2D but must adding the size for the next [3] array
int nubmers[][3] = {{ 29, 22 ,292},{ 29, 22 ,292}}
int nubmers[][3][2] = {
{{ 29, 22 ,292},{ 29, 22 ,292}},
{{ 29, 22 ,292},{ 29, 22 ,292}},
{{ 29, 22 ,292},{ 29, 22 ,292}}
}
getting the size for an array by sizeof for rows and columns
int array[] = { 2, 6,6,7};
// now get the size for array but * the datatTypes = 4 * 4 = 8
int size_array = sizeof(array);
// now get the number of elements 8 / 4 = 4
int size_array_elements = sizeof(array)/ sizeof(array[0]); // rows
int size_array_elements = sizeof(array[0])/ sizeof(array[0][02]); // columns
strcpy for change array Elements:
#include <stdio.h>
#include <string.h>
int main() {
char names[][10] = {"yossef", "sabry", "farouk"};
strcpy(names[0], "soliman");
for (int i = 0; i < sizeof(names) / sizeof(names[0]); i++) {
printf("%s \n", names[i]);
}
return 0;
};
- for more examples and functions string.h.md
continue:struct-typedef-enum.md
before:for-loop.md