# Array

## Lesson

**코딩도장 핵심요약**: [1D Array 핵심요약](https://dojang.io/mod/page/view.php?id=673)

![](/files/-MiVzCSuJ9ipndqlbkJG)

## Example Code

### Example 1

[C\_array1d\_example.c](https://github.com/ykkimhgu/Tutorial-C-Program/tree/main/pointer-array)

```
#include <stdio.h>
#include <stdlib.h>

void printVec(double *_vec, int _row);

int main()
{
	// Static Matrix Allocation  1-D array 
	// fixed array size and initial constant values
	double a[4] = { 1, 2, 3, 4 };
	double b[] = { 2, 3, 4, 5 };
	double c[4] = { 0 };

	// Print 1-D array element
	printVec(a, 4);

	system("pause");
	return 0;
}

void printVec(double *_vec, int _row)
{
	for (int i = 0; i<_row; i++)
	  printf("Vector[%d] = %f \n", i, _vec[i]);
	printf("\n");
}
```

***

## Exercise

* [Online C Compiler](https://www.onlinegdb.com/online_c_compiler)
* [Exercise Code](https://github.com/ykkimhgu/Tutorial-C-Program/tree/main/pointer-array)
* [Exercise-Solution Code](/ec/c-programming/c-programming-review/array.md)

### Exercise 1

[C\_array1D\_exercise.c](https://github.com/ykkimhgu/Tutorial-C-Program/tree/main/pointer-array)

Declare and define the following functions

`void addVec(float _src1[], float _src2[], float _dst[], int _vecLength);`

```cpp
void main() 
{
// Exercise 1 ***********************************************
printf(“Exercise 1\n");

float x[4] = {1,2,3,4};
float y[4] = {5,6,7,8};
float out[4] = { 0 };
float out_dotProduct = 0;

int vecLength = 4;

addVec(x, y, out, vecLength);
printf("addVector result (x + y): ");
printVec(out, vecLength);

system("pause");
}
```

<figure><img src="https://user-images.githubusercontent.com/38373000/187816291-db757178-c52d-46a7-820c-2daa8b926291.png" alt=""><figcaption></figcaption></figure>

### Exercise 2

[C\_array1d\_exercise2.c](https://github.com/ykkimhgu/Tutorial-C-Program/tree/main/pointer-array)

Assign array address to pointer ptr.

Print each element of 1D array by using pointer

```
#include <stdio.h>
int main(){
    int st[5] = { 1,2,3,4,5 };
    int* ptr;
    
    ptr = _______________;     
    for (int i = 0; i < 5; i++) {
        //  print each element by using pointer  e.g.  (ptr)
        
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ykkim.gitbook.io/ec/c-programming/c-programming-review/array.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
