강의

멘토링

커뮤니티

Inflearn Community Q&A

hatdoc1005's profile image
hatdoc1005

asked

Everything You Need to Know About C Language from the Author of Self-Study C Language

8.1 - Declaring and using arrays

array 요소 수

Written on

·

359

0

초반에 int array[n]와 같이 array 를 선언할때 n값을 안 정하고 선언할수 있나요? 
int array[];

scanf("%d",&array[0]); 를 for 으로 돌린다

이런식으로 만약 때에 따라 array 들어가는 값의 양이 달라지는 경우 (e.g. 점수 평균을 구할떄 학생마다 듣는 과목수가 다르다) 이런식으로 error가 나는데 어떻게 풀수 있나요?

c

Answer 1

0

저의 짧은 지식으로 생각 할 수 있는 것은...

scanf로 학생의 과목수를 받고 그 variable로 array를 initialize 하는 것은 어떨까요??

int num_courses; 

scanf("%d", &num_courses); //학생의 과목 수;

int array[num_courses];

for-loop..

hatdoc1005's profile image
hatdoc1005

asked

Ask a question