Lecture 9 Flashcards

POINTERS

1
Q

What is a pointer

A

A pointer is a memory address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a pointer variable

A

A variable that holds a memory address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the the compiler need to accesses data via memory address?

A

the size of the data type and how to interpret the memory bytes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the & operatory do?

A

The & operator gives the address of a variable (or a pointer to a variable)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is this code doing?
int count;
int *int_pointer = &count;

A

declaring the int variable count and declaring a pointer to an interger - (initializing the
pointer variable int_pointer to
the address of (or “pointer to”)
count)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the last line doing?
int count;
int *int_pointer = &count;
int x = *int_pointer;

A

It is indirectly accessing count using the * operator - also known as dereferencing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

include <stdio.h></stdio.h>

What is the output of this program?

int main (void)
{
char c = ‘Q’;
char *char_pointer = &c;
printf (“%c %c\n”, c, *char_pointer);
c = ‘/’;
printf (“%c %c\n”, c, *char_pointer);
*char_pointer = ‘(‘;
printf (“%c %c\n”, c, *char_pointer);
return 0;
}

A

Q Q
/ /
( (

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

include <stdio.h></stdio.h>

What is the output of this program?

int main (void)
{
int i1;
int i2;
int *p1;
int *p2;
i1 = 5;
p1 = &i1;
i2 = *p1 / 2 + 10;
p2 = p1;
printf (“i1 = %i, i2 = %i, *p1 = %i, *p2 = %i\n”, i1, i2, *p1, *p2);
return 0;
}

A

i1 = 5, i2 = 12, *p1 = 5, *p2 = 5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the equivalence of (*x).y?

A

x->y

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the equivalence of
datePtr = &today;
(datePtr).day = 5;
(
datePtr).month = 10;
(*datePtr).year = 2023;

A

datePtr = &today;
datePtr->month = 10;
datePtr->day = 5;
datePtr->year = 2023;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

include <stdio.h></stdio.h>

What is the ouput of this program?

struct intPtrs
{
int *p1;
int *p2;
};
int main (void)
{
struct intPtrs pointers;
int i1 = 100
int i2;
pointers.p1 = &i1;
pointers.p2 = &i2;
*pointers.p2 = -97;
printf(“i1 = %i, *pointers.p1 = %i\n”, i1, *pointers.p1);
printf(“i2 = %i, *pointers.p2 = %i\n”, i2, *pointers.p2);
return 0;
}

A

i1 = 100, *pointers.p1 = 100
i2 = -97, *pointers.p2 = -97

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a practical example that showcases the use of pointers

A

Linked-list or “node chain”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly