Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1) Compile, run, and study this C program: #include int main(void){ // note the array declaration format is slightly different from Java int myInts[] =

1) Compile, run, and study this C program:

#include

int main(void){

// note the array declaration format is slightly different from Java

int myInts[] = {0, 1, 2, 3, 4};

// declare an int pointer called pi and set it to point to the beginning of the array

// note that an array variable is a pointer to the beginning of the array

int *pi = myInts;

for(int counter = 0; counter

/* printf is also available in Java, but you may never have used it.

printf uses formatting codes like %p for pointer (addresses expressed in bytes in hexadecimal)

and %d for (decimal) int

*/

printf("Address %p: Value %d ", pi, *pi);

// incrementing a pointer changes it by the size of the type to which it points

pi += 1;

}

}

2) Add to this C program as follows:

a) Create an array of any five doubles and use a double pointer to iterate through it and print the addresses and values in the same way as the sample code iterates through the int array. The printf format code for a double is %f.

b) Do the same with an array of any five chars (for example, char myChars = {'J', 'o', 'h', 'n'}. The format code for a char is %c.

c) Add a multi-line comment (same syntax as Java) answering this question:

Suppose you had no other way to find out the size of an int, a double, or a byte (and note that, in C, these may actually vary between different compilers!) How could the output from your program help you answer these questions?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Usability

Authors: Jakob Nielsen, Raluca Budiu

1st Edition

0133122131, 9780133122138

More Books

Students also viewed these Programming questions

Question

4. (8 points) Fill in with =, >, >=,

Answered: 1 week ago