Defined a variable ptr of type unsigned short

Assignment Help Computer Engineering
Reference no: EM132013065

Programming Principles and Practice Assignment

Lab 7 - General C Programming

Q1. Download the file lab7q1.c from attachment containing source code which comes from the in-class examples for topic 12 (Intermediate C Constructs). You do not need to show a log of the download in your lab7.txt file. Then perform the following step-by-step directions.

(a) Copy lab7q1.c to lab7q1_modified.c.

Add to lab7q1_modified.c a single statement that will add to the table produced by the program the size of a variable that is of type unsigned long *. Make sure the additional output is the last line of the table. The output is to be two columns in width (the type and the size in bytes), and must line up with the existing columns of output produced by the program. Do not show a log of editing in your lab7.txt file. Perform a diff between lab7q1.c and lab7q1_modified.c.

(b) Demonstrate that your lab7q1_modified.c compiles cleanly even when using "-Wall -Wextra". Run your program from step 1a.

Q2. The sample program lab7q2.c compiles with warnings. If one ignores the warnings and executes the resultant executable file anyway, it results in a runtime error (the program "crashes"). Fix the program so that it compiles without warnings and executes without errors. Change only one statement in the program, and make the change as minimal as possible. Do not change any executable statements. Call your modified program lab7q2_fixed.c. You do not need to show a log of editing in your lab7.txt file. Instead, show a diff(1) of the original file and your lab7q2_fixed.c, a clean compilation of lab7q2_fixed.c, and the result of running the resultant binary executable file.

3. Suppose a C program contains the definition of an array of unsigned short integers. The array is defined as follows:

unsigned short us[6] = { 2, 4, 6, 8, 10, 12 };

Suppose that the following C statement

printf( "%zu %p\n", sizeof( unsigned short ), us );

, also in the program, produces

2 0x7fff5d11c866

(a) What would the following subsequent statement print?

printf( "%p\n", &us[3] );

(b) What would the following subsequent statement print?

printf( "%p\n", &us[3] + 2 );

(c) What would the following subsequent statement print?

printf( "%p\n", &us[3] + us[0] );

(d) Suppose that in this program there is also defined a variable ptr of type unsigned short *.

What will be printed as a result of the following subsequent statement combination?

ptr = &us[1]; printf( "%hu\n", *++ptr );

Lab 8 - General UNIX and Intermediate C Programming

Q1. UNIX/LINUX commands typically expect lines to be terminated by newline characters rather than carriage return characters. Lines terminated with carriage return characters can cause unusual and unexpected results.

(a) Download the file L8Q1.with_cr.txt.tar from the moodle pages for this lab. Use the tar(1) command to un-archive the file (to L8Q1.with_cr.txt).

(b) Use the pr(1) command in the same way as you did in question 2 of Lab 6 to output L8Q1.with_cr.txt (from part (a)) with line numbers.

(c) Use a UNIX pipeline involving hexdump -c and grep to show that L8Q1.with_cr.txt contains carriage return characters rather than, or in addition to, newline characters. The logic of the pipeline is that if grep(1) outputs anything (any lines), then L8Q1.with_cr.txt contains carriage returns. Note that hexdump -c represents a carriage return character by "\r" and newline by "\n" Make sure to have grep look for "\r" and not "r".

Q2. Download file lab8q2.c from the moodle pages for this lab. (You do not have to show a log of this in lab8.txt.) Copy it to lab8q2_modified.c. In lab8q2_modified.c complete the malloc() call to allocate an integer array a with the length of ten. Also complete the lines indicated in the file to obtain the lengths of arrays a and b using sizeof(). (You do not have to show a log of your editing in lab8.txt.) Once your editing is complete, run a diff(1) on the two files (lab8q2.c and lab8q2_modified.c) to show your modifications. Compile the code using options -Wall and -Wextra and show there are no warnings. Execute the program, and copy its output to lab8.txt.

In lab8.txt, explain why two different sizes are displayed to the console when your program runs. In other words, why are the lengths of arrays a and b not the same? If you do not understand, please ask for assistance from the lab instructor.

Q3. Download lab8q3_incomplete.c from the moodle pages for this lab. (You do not have to show a log of this in lab8.txt.) It is a revision of example_60.c from class. There is one statement in the program that is incomplete. That statement calculates the address of the (ith, jth) component of an element in a 2D vector. In this question you need to provide the correct expression and complete the statement. Note that you cannot use the unary & operator in your expression. The completed statement should only occupy a single line in the source file.

Copy lab8q3_incomplete.c to lab8q3.c and, with a text editor, complete the partial statement in lab8q3.c as described above. (You do not need to show a log of your editing in lab8.txt.) Compile lab8q3.c using -Wall and -Wextra and run it. Make sure that the results are what they should be. Finally, produce a diff(1) of the two files (lab8q3_incomplete.c and lab8q3.c) to indicate your modification.

Note - Only need the lab7 - Q1, Q2, Q3, and lab8 - Q1, Q2, Q3.

Attachment:- Assignment Files.rar

Reference no: EM132013065

Questions Cloud

How is the ipv6 addressing different from that of ipv4 : How is the IPv6 addressing different from that of IPV4? How about a network portion and the host portion of the network, how is that different?
Identify the life-span time period between given age : Zastrow and Kirst-Ashman, use the term young and middle adulthood to identify the life-span time period between age 18 and 65. This classification distinguishes
Advantage and disadvantage for web-dbms integration : List at lest at least 5 items for advantage and disadvantage for Web-DBMS integration. Please point out the main reason for each items.
What do twin and adoption study tell about effect of nature : What do twin and adoption studies tell us about the effects of nature (i.e., genetic influences) and nurture (i.e., environmental influences).
Defined a variable ptr of type unsigned short : CMPT 214: Programming Principles and Practice Assignment. Suppose that in this program there is also defined a variable ptr of type unsigned short *
Organize the code capable of throwing : -Organize the code capable of throwing an exception of type ParseException as a try block.
Four locations hooked up to the internet : What were the first four locations hooked up to the Internet (ARPANET)? Which came first, the Internet or the World Wide Web?
How nutrition needs change throughout the lifecycle : Describes how nutrition needs change throughout the lifecycle and identifies ways to improve an individual's nutritional intake.
Various approaches of implementing databases internet : The approach to implement database Internet connectivities. search for various approaches of implementing databases Internet

Reviews

len2013065

6/9/2018 1:04:16 AM

Detailed Question: only need the lab7 Q1 Q2 Q3 and lab8 Q1 Q2 Q3. Lab Details - This lab is out of a total of 11 marks, with each question (1a, 1b, 2, 3a, etc.) being worth one mark except for 4 and 5, which are worth 2 marks each. When you have completed the exercises below, you should prepare a plain text log file named lab7.txt as described in the Submission Instructions posted on the course Moodle. For this lab, submit the following files: lab7.txt. Remember to put your name, student number and NSID at the beginning of any ?les you are submitting. Special Directions - You can use either tuxworld or one of the ismac machines for this lab. However record in lab7.txt which you used as the answers to the questions vary slightly between machines. For questions 1, 2, 4 and 5, you will need to download auxilary C source code files. Look for the link Moodle under this lab’s section.

len2013065

6/9/2018 1:04:11 AM

Lab Details - This lab is out of a total of 17 marks; the number of marks allocated to each question is indicated below. When you have completed the exercises below, you should prepare a plain text log file named lab8.txt as described in the Submission Instructions posted on the course Moodle. For this lab, submit the following files: lab8.txt and test_math.c from question 5. Remember to put your name, student number and NSID at the beginning of any files you are submitting. Special Directions - You can use either tuxworld or one of the ismac machines for this lab. However record in lab8.txt which you used as the answers to the questions vary slightly between machines.

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd