char array

Hello, I am new to doing this and am having some trouble. the directions I have are to use "char array" instead of "int array" to determine how many bytes each element has. I have tried changing int array to char array but get an error. Any suggestions on what I am doing wrong. Many thanks for the help.

#include "simpletools.h" // Include simpletools library

int array[5] = {11, 13, 17, 19, 23}; // array

int main() // Main function

print("array start address = %d \n\n", array); // Display array value

for(int i = 0; i < 5; i++)
print(" array[%d] = %d \n", i, array); // Display array value
print("&array[%d] = %d \n", i, &array); // Display array address


  • 3 Comments sorted by Date Added Votes
  • Hal AlbachHal Albach Posts: 698
    edited April 2017 Vote Up0Vote Down
    Running your program on my activity board yields no errors, whether array is int or char.
    However, your final print statements will only output the address of array, 8036 in my case. Adding the subscript i to array and &array yielded what you wanted per your comments.
    print(" array[%d] = %d \n", i, array[i]); // Display array value
    print("&array[%d] = %d \n", i, &array[i]); // Display array address
    Florida, between St. Petersburg and the Gulf of Mexico

    Do not look directly into laser with remaining good eye...
  • Saying "get an error" is not very helpful. Giving the error description and location is much more useful.
  • Thanks for the feedback, I will make sure to include the error description.
Sign In or Register to comment.