Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Download program lab2C0.c, compile and run the program. (C programming) Observe that we use marco #define SIZE 20 to define a constant, avoiding magic numbers.

Download program lab2C0.c, compile and run the program. (C programming) Observe that we use marco #define SIZE 20 to define a constant, avoiding magic numbers. This is one of the two common ways to define a constant in C. When the program is compiled, the pre-processor replaces every occurrence of SIZE with 20. Observe the strange values for elements of array k. Run it again and you might see the change of the strange values. The point here is that, in Ansi-C, an array element is not given an initial value such as 0, rather a garbled value that is randomly generated is given. Modify the declaration int k[SIZE]; to int k[SIZE] = {3,5}; Compile and run it again, what do you see? The point here is that if you specify initial values for one or more of the first few elements of the array, the rest elements of the array gets initial value 0. Based on this trick, and without using loop, modify the declaration of k so that k is initialized to all 0s, as shown in the sample output below. Observe that for char array msg, which was initilized with a 11 character string literal "Hello World", the memory size allocated by compiler is 12 bytes. (Observe sizeof operator is used to get the memory size of array.) The extra 1 byte is used to store the null character '

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

Algorithmic Trading Navigating The Digital Frontier

Authors: Alex Thompson

1st Edition

B0CHXR6CXX, 979-8223284987

More Books

Students also viewed these Databases questions