Programming Exam Review

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What does the Rand operator do ?

This generates a random number between the ranges.

What does the modulus operator give us ?

This gives us the remainder

Formula for Pre Incrementation(++a)

"Increment the value "a"" "New value is assigned to a" int i=1 int j=++i i=1+i j=i i=2 j=2

what is the place holder for char in scanf or print f functions

%c

How do we declare the pointer

*p

rand()%100

0-99

rand()%100+1

1-100

rand()30+1985

1985-2014

14%12

2

can you create arrays of a structure

YES

what is the actual value of a pointer

a long hexadecimal number

what is P without *

address

What do arrays name act as

constant pointers

x or X

is used to print hexadecimal numbers

P=&a; returns what

would return the address of a

fputs

write a line to a file int fputs(const char *s, FILE *stream);

what is the place holder for integer in scanf and print f functions

%d

what is the place holder for floats in scanf or print f functions

%f

Two LEDs are mapped to Port 1 of the microcontroller. Port 1 is 8-bit. The green LED is mapped to pin 5 and the red LED is mapped to pin 2. Port 1 is bi-directional, therefore, we can set the direction of the pins by writing the P1DIR. How can we initialize the two LED pins to output?

P1DIR |= 0x24;

Two LEDs are mapped to Port 1 of the microcontroller. Port 1 is 8-bit. The green LED is mapped to pin 5 and the red LED is mapped to pin 2. The code below blinks the two LEDs such that the red LED is blinking at double the speed of the green LED. This pattern can be achieved by initializing the LEDs to: (Green, Red) = (OFF, OFF) Then, in the loop, this is the repeating pattern: (Green, Red) = (ON, ON) (Green, Red) = (ON, OFF) (Green, Red) = (OFF, ON) (Green, Red) = (OFF, OFF) What are the missing lines of code?

P1OUT ^= 0x24; ........... P1OUT ^= 0x04; ......... P1OUT ^= 0x24; .......... P1OUT ^= 0x04;

Two LEDs are mapped to Port 1 of the microcontroller. Port 1 is 8-bit. The green LED is mapped to pin 5 and the red LED is mapped to pin 2. Assuming that the direction has been initialized to output, we can read/write to the pins by using P1OUT. How can we initialize the LEDs to ON?

P1OUT |= 0x24;

size_t strlen(const char *s );

Returns the number of characters (before NULL) in string s

What data structure in C store valuables of multiple of different types?

Structures

how many bytes is a pointer for a 32 bit machine

4 bytes

what is the size of for this code char*pc; printf("sizeof(pc)=%u\n",sizeof(pc));

4 size of specific pointer does not matter on the variable type

how many bites is a pointer for a 64 bit machine

8 bytes

What is a structure

A structure is a collection of members that can be of different data types

Pointer to structure

The second method to access a structure member is through a pointer to the structure. Using a pointer to a structure, the arrow operator (->) and the name of a member. printf("sp->id = %d\n", sp->id);

What does % mean

This means modulus

What is a pointer

Variables that store address of another variable

dot operator

a way to access a structure name struct Student s; s.id = 101;

Example of Size Of function a) int a[6] >sizeof (a) b) double d[3][4] >sizeof(d)

a) 24 b)96

Accessing members of a structure using pointers?

Arrow operator. ptr->name

How do you find the size of an Array?

the bytes of the data set multiplied by the array size

The strlen function returns

the number of characters in a string excluding the null character

&&

this means AND which is multiplication

i

used to print decimal number

Formula for post incrematation(a++)

value assigned to a" "a is incremented" a++----a="old value" a=a+1 int i=1; int j=i++ j=i and i=i+

*p

value at adress

int strcmp(const char *s1, const char *s2)

Compare string s1 to s2. - if Return value < 0 then it indicates str1 is less than str2. - if Return value > 0 then it indicates str2 is less than str1. - if Return value = 0 then it indicates str1 is equal to str2.

sizeof(str)

size of string eg) Char str[10]="hello" =10

char *gets(char *s);

Inputs characters from the standard input into the array s until a newline or end-of-file character is encountered. A terminating null character is appended to the array.

Assuming that string1 = "hello" and string2 = "hello world", Which of the following returns 0?

strncmp(string1, string2, 5);

how do you copy a string up to certain number length

char *strncpy(char *s1, const char *s2, size_t n) Copies at most n characters of string s2 into s1. If there are fewer than n characters in s2 before the null terminating character, then null characters are added into s1 as padding until the specified number has been written.The value of s1 is returned

how do you copy a string

char*strcpy(char*s1,const char*s2) copies string s2 into s1. The value of s1 is returned

fscan/fprints

file processing equivelent to printf and scanf

When to use fgets

for a string with white space

Which are the loops in C?

for,while,do while,if else,if.

*(p+1)

move position

*p+1

move value

Given pointer and variable x equal certain value , how to we get pointer to point to values ?

must use *in order to get the value

char *strPtr = "String" ,sizeof(strPtr)

one but each byte is worth 4

Which operations can be taken on Pointers

p+i or p+=i

fgets

read a line from a file syntax:char *fgets(char *s, int n, FILE *stream);


Set pelajaran terkait

2.1 Basic of Functions and Their Graphs

View Set

Solving Quadratic Equations: Square Root Property

View Set

Wk 4 Practice: Ch. 8, Performance Management

View Set

CH 28 QUIZ: Face and Neck Injuries

View Set

RH134 - Chapter 7: Managing Logical Volumes

View Set