[Solved] CSC3320 Lab 9

$25

File Name: CSC3320_Lab_9.zip
File Size: 122.46 KB

SKU: [Solved] CSC3320 Lab 9 Category: Tag:
5/5 - (1 vote)

Rate this product

Purpose: Learn how to use array in C. Understand the basic memory address in C.

Part 1:

Write a C program named as getMostFreqChar.c that finds the most frequent letter from the input via ignoring the case sensitive and prints out its frequency. For example, sample outputs could be like below

$cat test.txt

This is a list of courses.CSC 1010 COMPUTERS & APPLICATIONS

$./getMostFreqChar test.txtThe most frequent letter is s. It appeared 8 times.

Run the C program, attach a screenshot of the output in the answer sheet.

Part 2:

When a variable is stored in memory, it is associated with an address. To obtain the address of a variable, the & operator can be used. For example, &a gets the memory address of variable a. Lets try some examples.Write a C program addressOfScalar.c by inserting the code below in the main function.

Questions:

1) Run the C program, attach a screenshot of the output in the answer sheet.2) Attach the source code in the answer sheet2) Then explain why the address after intvar is incremented by 4 bytes instead of 1 byte.

1234567891011

12

// intialize a char variable, print its address and the next addresschar charvar = '';printf("address of charvar = %p
", (void *)(&charvar));printf("address of charvar - 1 = %p
", (void *)(&charvar - 1));printf("address of charvar + 1 = %p
", (void *)(&charvar + 1));
// intialize an int variable, print its address and the next addressint intvar = 1;printf("address of intvar = %p
", (void *)(&intvar));printf("address of intvar - 1 = %p
", (void *)(&intvar - 1));printf("address of intvar + 1 = %p
", (void *)(&intvar + 1));

Part 3:Write a C program addressOfArray.c by inserting the code below in the main function.

1234567891011

12

// initialize an array of intsint numbers[5] = {1,2,3,4,5};int i = 0;
// print the address of the array variableprintf("numbers = %p
", numbers);
// print addresses of each array index
do {    printf("numbers[%u] = %p
", i, (void *)(&numbers[i]));    i++;
} while(i < 5);
// print the size of the arrayprintf("sizeof(numbers) = %lu
", sizeof(numbers));

Questions:

1) Run the C program, attach a screenshot of the output in the answer sheet.

2) Check the address of the array and the address of the first element in the array. Are they the same?

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CSC3320 Lab 9
$25