Which of the following is a valid C statement Explain what e

Which of the following is a valid C statement? Explain what each valid statement does. For invalid statements, explain the problem. int items [5]; int items []; int items = {3, 7, 2}; int items [] = {3, 7, 2}; int items [3] = {3, 7, 2}; Write a C statement that will create an integer array named nums, of length 3. Using a for-loop, initialize all of the elements in the array to 10.

Solution

Below is the answer to your question 1

a) int items [5] :- Here items is a variable which can hold upto 5 numbers.

b) int items [ ] :- This is not a valid statement as initialization of an array is not done nor the number has been specified as to what extent can array hold the numbers.

c) int items = {3,7,2} :- Invalid statement as we are trying to assign a number variable with different values at a time. A single value assignment would have worked

int item = 3 or in case of array int items[] = {3,7,2} would have sufficed.

d) int items[] = {3,7,2} :- This will create an array of integers with name items which will have 3 values.

e) int items[] = {3,7,2} :- This will create an array of integers with name items which will have 3 values

 Which of the following is a valid C statement? Explain what each valid statement does. For invalid statements, explain the problem. int items [5]; int items []

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site