Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include void displayInfo(char charArray[], int physicalSize, int logicalSize); /**This program is to observe the elements in a character array and how the string

#include  #include  #include  void displayInfo(char charArray[], int physicalSize, int logicalSize); /**This program is to observe the elements in a character array and how the string methods in string.h interpret a character array as string. * The output I got from last run is as following: ------------------------------------------------------------------------------------------------------------- Physical size: 20 Logical size: 11 String------->|ABCDEFGHIJ@|<----------End of string Index-------->| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19|<---------End of array index Character---->| A B C D E F G H I J @ `  @ |<---------End of array ASCII-------->| 65 66 67 68 69 70 71 72 73 74 64 0 0 0 0 0 96 24 64 0|<---------End of ASCII ------------------------------------------------------------------------------------------------------------- * Run the program on your computer, observe the output, and answer the following questions: * 1. Do you see the same logical size? Why? * 2. Do you see the same elements in your output? If not, why? * 3. Run it after each of the following different operations and observe the output again * a). Run some other programs; * b). Close your IDE and relaunch. * c). Do anything that may affect the memory usage * Do you see the same output as the first time you run the program? * 4. What should we do to ensure the string terminates properly? * */ int main(void) { int physicalSize = 20; int logicalSize = 10; char charArray[physicalSize]; int i = 0; //Put character 'A' 'B' ... into the first logicalSize units for(; i < logicalSize; i ++){ charArray[i] = 'A' + i; } displayInfo(charArray, sizeof(charArray), logicalSize); return 1; } void displayInfo(char charArray[], int physicalSize, int logicalSize){ puts("-------------------------------------------------------------------------------------------------------------"); int i = 0; //size info printf("Physical size: %d ", physicalSize); printf("Logical size: %d ", strlen(charArray)); //Output the array as a string printf("String------->|%s|", charArray); printf("<----------End of string ", charArray); //Display the indexes of the array printf("Index-------->|"); for(i = 0; i < physicalSize; i ++){ printf("%3d", i); } printf("|<---------End of array index "); //Output the array elements character by character //(each character takes 3 spaces in the output)); printf("Character---->|"); for(i = 0; i < physicalSize; i ++){ printf("%3c", charArray[i]); } printf("|<---------End of array "); //Output the encoding of the array printf("ASCII-------->|"); for(i = 0; i < physicalSize; i ++){ printf("%3d", charArray[i]); } printf("|<---------End of ASCII "); puts("-------------------------------------------------------------------------------------------------------------"); }

PLEASE ANSWER THE 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

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions

Question

Are there any disadvantages to this tactic?

Answered: 1 week ago