Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

/* * Return 1 if the addresses stored in ptr1 and ptr2 are within the * *same* 64-byte aligned block of memory. Check the spec

/* * Return 1 if the addresses stored in ptr1 and ptr2 are within the * *same* 64-byte aligned block of memory. Check the spec for examples if you are * confused about what this means. Return zero otherwise. * Operators / and % and loops are NOT allowed. * * ALLOWED: * Pointer operators: *, & * Binary integer operators: -, +, *, <<, >>, ==, ^ * Unary integer operators: !, ~ * Shorthand operators based on the above: ex. <<=, *=, ++, --, etc. * * DISALLOWED: * Pointer operators: [] (Array Indexing Operator) * Binary integer operators: &, &&, |, ||, <, >, !=, /, % * Unary integer operators: - */ int withinSameBlock(int *ptr1, int *ptr2) { // Your code here return 2; }

/* * Return 1 if ptr points to an element within the specified intArray, 0 otherwise. * Pointing anywhere in the array is fair game, ptr does not have to * point to the beginning of an element. Check the spec for examples if you are * confused about what this method is determining. * size is the size of intArray in number of ints. Can assume size != 0. * Operators / and % and loops are NOT allowed. * * ALLOWED: * Pointer operators: *, & * Binary integer operators: -, +, *, <<, >>, ==, ^ * Unary integer operators: !, ~ * Shorthand operators based on the above: ex. <<=, *=, ++, --, etc. * * DISALLOWED: * Pointer operators: [] (Array Indexing Operator) * Binary integer operators: &, &&, |, ||, <, >, !=, /, % * Unary integer operators: - */ /* int withinArray(int * intArray, int size, int * ptr) { // Your code here return 2; } */

/* * In C characters are are terminated by the null character ('\0') * given a pointer to the start of the string return the length of this string. * (The null character is not counted as part of the string length.) * * ALLOWED: * Pointer operators: *, & * Binary integer operators: -, +, *, ==, !=, <, > * Unary integer operators: ! * Shorthand operators based on the above: ex. <<=, *=, ++, --, etc. * Control constructs: for, while * * DISALLOWED: * Pointer operators: [] (Array Indexing Operator) * Binary integer operators: &, &&, |, ||, <<, >>, ^, /, % * Unary integer operators: ~, - */ int stringLength(char * s) { // Your code here return 2; }

/* * In C characters are are terminated by the null character ('\0') * given a pointer to the start of a string and a pointer to a second string, * append the second string to the first. * (The string should be completed by a null character.) * * ALLOWED: * Pointer operators: *, & * Binary integer operators: -, +, *, ==, !=, <, > * Unary integer operators: ! * Shorthand operators based on the above: ex. <<=, *=, ++, --, etc. * Control constructs: for, while * * DISALLOWED: * Pointer operators: [] (Array Indexing Operator) * Binary integer operators: &, &&, |, ||, <<, >>, ^, /, % * Unary integer operators: ~, - */ void stringAppend(char * d, char * s) { // Your code here }

/* * Change the value pointed to by ptr byte-by-byte so that when returned as an integer * the value is 351351. * * Hint: Remember that an int is 4 bytes. * * Hint: Remember how little endian works for data storage, how is it different between an multiple bytes(int) and a single byte? * * Hint: It will be easiest to start convert 351351 into binary form and starting seeing how the endian works from there. * * ALLOWED: * Pointer operators: *, & * Binary integer operators: -, +, * * Shorthand operators based on the above: ex. +=, *=, ++, --, etc. * Unary integer operators: ! * * DISALLOWED: * Pointer operators: [] (Array Indexing Operator) * Binary integer operators: &, &&, |, ||, <, >, <<, >>, ==, !=, ^, /, % * Unary integer operators: ~, - */ /* int endianExperiment(int* ptr) { char *bytePtr; // Your code here return *ptr; } */

/* * Selection sort is a sorting algorithim that works by partitioning the array into * a sorted section and unsorted section. Then it repeatedly selects the minimum element * from the unsorted section and moves it to the end of the sorted section. * * So the pseudo-code might look something like this: * arr - an array * n - the length of arr * * for i = 0 to n - 1 * minIndex = i * for j = i + 1 to n * if arr[minIndex] > arr[j] * minIndex = j * end if * end for * Swap(arr[i], arr[minIndex]) * end for * * Implement selection sort below, it might be helpful to use the swapInts function you * defined earlier. * * ALLOWED: * Pointer operators: *, & * Binary integer operators: -, +, *, ==, !=, <, > * Unary integer operators: ! * Shorthand operators based on the above: ex. +=, *=, ++, --, etc. * Control constructs: for, while, if * Function calls: swapInt() * * DISALLOWED: * Pointer operators: [] (Array Indexing Operator) * Binary integer operators: &, &&, |, ||, <<, >>, ^, / * Unary integer operators: ~, - */ void selectionSort(int arr[], int arrLength) { int i, j, min_index; // Your code here }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started