Consider the following C code fragments and answer the associated questions. Ass
ID: 3578265 • Letter: C
Question
Consider the following C code fragments and answer the associated questions. Assume that the code is running on a Nios II processor which is little endian. The Altera data types have been used which indicate data size explicitly. Note that some code fragments may not give useful results.
1.Describe the result of the printf() statement in the following code fragment.
alt_32 test(alt_32 a, alt_8 b)
{
return b >> 1*a;
}
main()
{
printf("%x ", test);
}
2.What is the result of the printf() statement in the following code fragment?
alt_8 a[ ] = {0x11, 0xa2, 0x36, 0x55, 0x44, 0x33};
printf("%x ",* ((alt_16 * ) a + 2));
Explanation / Answer
1) printf("%x ", test);
Above line prints address of function test . function is not called with argument so printf treat it as variable and prints the address of the function.
2) printf("%x ",* ((alt_16 * ) a + 2));
It prints 3344
Data size is 16 bits , so there are two bytes for each array element. There are three elements in array.Base address of array a + 2 gives address staring with 3rd element in array ie 0x44 , printf prints 2 byte from higher byte and lower byte order ie 33 44
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.