CPSC 1020 Final Exam 2023 with correct answers
typedef struct Car car_t; struct car_t { char make[20]; int year; char model[20]; }; creating a c style struct car_t * carPtrs[10]; int i; for(i = 0; i 10; i++) { carPtrs[i] = (car_t*) malloc(sizeof(car_t));; } creating an array of car_t pointers and dynamically allocating memory for them void type of pointer returned by malloc . operator used to access members of a struct - operator used to access member of a struct pointer runtime the point at which we know how much space to use for a variable stdlib header file that must be included to use malloc free() function to call on a malloced pointer void(*numPtr)(int); function pointer to the function printNum(int); numPtr = &printNum; initializing the function pointer to point to the function printNum numPtr(54); using the function pointer to pass the value of 54 to the function int arr = (int)malloc(rowcolsizeof(int)); example of mallocing for a 1D array free(ptr); prototype for freeing a 1D array for(i=0; in; i++){ free(ptr[i]); } how to free a 2D array namespace provides a method fro preventing name conflicts in projects .eof() function to determine if the file is at its end .good() function to determine if the file was read all right setw(n) sets a minimum print field width of size n for the next value output fixed displays floating-point numbers in fixed point form showpoint causes a decimal point and trailing zeros to be displayed for floating point numbers, even if there is no fractional part setprecision(n) sets the maximum number of digits in the number double num = 3.7; int val; val = (int) num; c style casting val = static_castint(num); c++ style casting const is an actual variable with a memory location, const must be given a value when declaring it; #define is not a variable, and instead is a preprocessor directive(text substitutive), #define must be given a value when creating differences between const and #define
Written for
- Institution
- CPSC 1020
- Course
- CPSC 1020
Document information
- Uploaded on
- June 19, 2023
- Number of pages
- 4
- Written in
- 2022/2023
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
-
cpsc 1020 final exam