0% found this document useful (0 votes)
58 views1 page

Part I. Code Tracing (Score: - / 22 PTS) Program23.c (Pointer Basics) Types.h

1) This code tracing exercise analyzes a C program with pointer basics. 2) The main function declares several unsigned char variables and pointers, assigns values, calls the func function passing the address of a and the value of b, and prints outputs. 3) The func function prints the values pointed to by x and the value of y, doubles the value pointed to by x, increments y, prints the new values, and returns the sum of the values pointed to by x and y.

Uploaded by

maki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views1 page

Part I. Code Tracing (Score: - / 22 PTS) Program23.c (Pointer Basics) Types.h

1) This code tracing exercise analyzes a C program with pointer basics. 2) The main function declares several unsigned char variables and pointers, assigns values, calls the func function passing the address of a and the value of b, and prints outputs. 3) The func function prints the values pointed to by x and the value of y, doubles the value pointed to by x, increments y, prints the new values, and returns the sum of the values pointed to by x and y.

Uploaded by

maki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Course: DTPH C Programming

Trainee Number:
Trainee Name:

Code Tracing Exercise 7

Part I. Code Tracing (Score: ____ / 22 pts)

Program23.c (Pointer Basics) types.h


#include <stdio.h> #define U1 unsigned char
#include "types.h" #define U2 unsigned short
#define U4 unsigned long
U1 func(U1 *x, U1 y) {
printf("13)%d¥n", *x); #define S1 signed char
printf("14)%d¥n", y); #define S2 signed short
*x *= 2; #define S4 signed long
y = y + 3;
printf("15)%d¥n", *x);
printf("16)%d¥n", y);

return *x + y;
}

int main() { What is the output on the console when the


U1 a; main function is executed? (22 pts.)
U1 b = a = 1;
U1 *t; 1)
U1* u; 2)
U1 *v, *w; 3)
U1* x, y; 4)
U1 *z = &a; 5)
6)
printf("1)%d¥n", a); 7)
t = &a; 8)
a = 2; 9)
printf("2)%d¥n", t); 10)
printf("3)%d¥n", *t); 11)
*t = 3; 12)
printf("4)%d¥n", a); 13)
printf("5)%d¥n", &a); 14)
15)
printf("6)%d¥n", b); 16)
w = &b; 17)
v = w; 18)
w = &a; 19)
printf("7)%d¥n", *v); 20)
printf("8)%d¥n", *w); 21)
u = w = v; 22)
printf("9)%d¥n", *w);
printf("10)%d¥n", *u);

printf("11)%d¥n", sizeof(x));
printf("12)%d¥n", sizeof(y));
x = 5;
y = func(&a, b);
printf("17)%d¥n", y);
printf("18)%d¥n", a);
printf("19)%d¥n", b);
printf("20)%d¥n", x);
printf("21)%d¥n", *z);
printf("22)%d¥n", *x);
return 0;
}

You might also like