+ 6

int arr[] = {1, 2, 3, 4, 5}; (int x = 0; x < 5; x++) { printf("%d", [x]); }

17th Apr 2022, 4:14 PM
Arafat Rahon
Arafat Rahon - avatar
1 Answer
0
printf FORMAT [ARGUMENT]... Your issue is in your printf usage. By using %d you are requesting to Print an integer as a signed decimal number. See Integer Conversions, for details. ‘%d’ and ‘%i’ are synonymous for output, but are different when used with scanf for input. https://www.gnu.org/software/libc/manual/html_node/Table-of-Output-Conversions.html next your argument to use %d is only [x] which in this case would represent nothing. your int arr = {1,2,3,4,5} set up an array of integers with a variable named arr and indexed 0 - 4 such that: {[arr[0]] = 1, [arr[1]] = 2, [arr[2]] = 3, [arr[3]] = 4 , [arr[4]] = 5} So what you need is: printf("%d", arr[x]); which will produce: 12345user$ the 12345 comes from the program the user$ is your terminal prompt because of no new line.
17th Apr 2022, 9:46 PM
William Owens
William Owens - avatar