Computer Science > EXAM > CECS 325 Midterm Review Exam (REAL) | With Verified Answers (All)
CECS 325 Midterm Review Exam (REAL) | With Verified Answers What is the first thing you need to do in order to use pthread? #include <pthread.h> How would you compile a C++ program with multithread ... ing capabilities in the Linux Terminal? c++ program.cpp -lpthread -o program What is the first parameter in pthread_create? thread, initialized as pthread_t t1; on a previous line in order to pass information on the thread through a variable What is the 2nd parameter in pthread_create? attribute, not necessary for our class but it's a pointer to a structure that can define thread attributes such as stack address etc What should you pass through the 2nd parameter in pthread_create by default? NULL What is the 3rd parameter in pthread_create? the function in which you want to run through the thread, EX: mySort Do functions in the 3rd parameter of pthread_create include their own parameters? NO, the 4th parameter of pthread_create includes the function's parameters. What is the 4th parameter in pthread_create? arg (arglist), pointer to void that contains the arguments to the function defined in the earlier argument What is the function to terminate a thread? void pthread_exit(void *retval); What is the function to make a thread wait? pthread_join(thread1, NULL); Why is the pthread_join function usually required? We need to wait till the threads are complete, otherwise the main function will continue while the threads are processing, risking termination of the program(return 0;) before the threads are completed. How do you declare a string in C/C++? (cstring) char s[5]; can visualize it as an array with 5 element slots What should always be included at the end of a C/C++ string? (cstring) \0, or null pointer Is char a[4] = ('a', 'b', 'c', 'd') valid? (cstring) no, assigning 5 characters to a string that has 4 characters. \0 is automatically initialized as the end of any given string. What is the strlen() function? takes a string as its argument and returns the string's length, excluding the \0 at the end. ''' int strlen(char n []) { int i = 0; while (n[i++] != '\0') {} return i - 1; } ''' What is the difference between pass by value and pass by reference? When passing by value, the value passed in a parameter is not changed after the function operations, whilst passing by reference the value does change. Pass by reference: myfunc(& int x){ x+= 5; } int main() { int x = 10; myfunc(x); print(x) } OUTPUT: 15 Pass by value: myfunc(int x){ x+= 5; } int main() { int x = 10; myfunc(x); print(x) } OUTPUT: 10 What is sizeof()? returns the size of either a variable, type or expression allocated in the memory in bytes. What is the function of the linux command "cd"? to change directories and change between file lists What is the function of the linux command "ls"? most commonly used command, lists all folders and files in a particular file path What is the function of the linux command "man"? also known as the manual command, man interfaces the system manual to any given command. What is the function of the linux command "cat"? short for concatenate, concatenate files and print on the standard output What is the function of the linux command "mkdir"? create a directory What is the function of the linux command "chmod"? widely used by admins, sets file permissions on a folder or file What is the function of the linux command "rmdir"? remove a file or directory from a location What is the function of the linux command "touch"? creating, changing, and modifying file timing information What is the function of the linux command "locate"? also known as find command, used to locate a particular file : locate -i final will locate files with the name final What is the function of the linux command "clear"? clears up the command prompt screen What is the function of the linux command "rm"? removes a particular file what is the function of the linux command "mv"? move a file to another directory EX: mv/myfolder/appli/myapps /myfolder/newapp/firstapp what is the function of the linux command "curl"? optionally installed linux package, used to extract info from URLs or IP addresses what is the function of the linux command "echo"? prints specified text in terminal window EX: echo Hello World what is the function of the linux command "free"? displays amount of free and used memory in the system what is the function of the linux command "groups"? display a list of all groups aka groups of users what is the function of the linux command "head"? displays the first 10 lines of a given file EX: head numbers.txt what is the function of the linux command "history"? displays a list of previously used commands what is the function of the linux command "passwd"? changes password EX: sudo passwd yo what is the function of the linux command "ping"? checks network connection and troubleshooting networking issues EX: ping 8.8.8.8 what is the function of the linux command ".alias"? tells the shell to return one string with a different string while performing the commands what is the function of the linux command "ZIP"? confines and packages files EX: $zip newfile.zip name.txt what is the function of the linux command "dd"? versatile command used for converting and copying files what is the function of the linux command "chown"? enables users to modify the user and/or group control of an assigned file, directory, or representative link what is the function of the linux command "sudo"? "Super User DO" command, very important, prefix applied to any command that only superusers can execute. lets users operate applications as a different user, by default the root what is the function of the linux command "cal"? displays the current calendar date, can be display different days, entire calendar, julian date etc with various commands what is the function of the linux command "chage"? used by admins to change the expiry data of a user password what is the function of the linux command "df"? retrieves file system data what is the function of the linux command "bc"? command line calculator what is the function of the linux command "uname"? unfolds system data, like operating system, version, processor etc. struct student { string name; int age; char grade; }; student s1, *sptr; sptr = &s1; s1.name = "Dakota"; what code would you use to set Dakota's age to 23? sptr->age = 23; What does Amdahl's Law describe? sequential work will limit speedup due to parallelism Is a separate header file to a cpp required? no, although its handy for larger classes int nums[6] = {2, 4, 6, 8, 10, 12}; printArray(nums); void printArray(int n[ ]) { for(int i=0, i<n.size; i++) cout << n[i]; } what will printArray function actually print out? none due to n.size, arrays do not keep track of their own size. would need to use sizeof() int size = sizeof(arr)/sizeof(arr[0]); The fibonacci function is a recursive function. Each time the function gets called in a recursive loop, what type of memory is used to store the contents and state of the program? Stack int A[ ] = {0, 1, 2, 3, 4, 5}; int *ptr = A; How could you print 3 to the screen? cout << ptr[4]; arrays are more or less constant pointers in C++, therefore the above line is legal int x = 10; int y = 20; int z = mystery(x, y); cout << z << "/" << x + y; int mystery(int &a, int b) { a += 15; b += 5; return a + b; } What will print? 50/45 int&a meaning the value of x will change after the function finishes meanwhile y wont. x = 10 + 15 = 25 x+y = 45 int showElement(int A[ ], int index) { cout << A[index]; } What would be equivalent to the cout above? cout << *(A+ index) "A" itself is the address, doing "+ index" moves you to corresponding address in memory "*" dereferences that address so you can get the value of what’s at the address what is another name for cstring? null terminated character array void func(char * ptr) { cout << ptr; } what is the mode of passing used in the function passing parameter ptr? pass by value what is the function of strcmp()? compares two strings character by character, and returns 0 if both strings are equal. int strcmp (const char str1, const char str2); where are strcmp(), strlen() and strcpy() sourced from/defined in? string.h header file; i.e. #include <string.h> [Show More]
Last updated: 8 months ago
Preview 3 out of 9 pages
Loading document previews ...
Buy this document to get the full access instantly
Instant Download Access after purchase
Buy NowInstant download
We Accept:
Can't find what you want? Try our AI powered Search
Connected school, study & course
About the document
Uploaded On
Mar 25, 2025
Number of pages
9
Written in
All
This document has been written for:
Uploaded
Mar 25, 2025
Downloads
0
Views
44
Scholarfriends.com Online Platform by Browsegrades Inc. 651N South Broad St, Middletown DE. United States.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Scholarfriends · High quality services·