Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

// // c-datatypes.c // #include <stdio.h> #include <stdlib.h> #include <string.h

ID: 3783304 • Letter: #

Question

//
// c-datatypes.c
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <inttypes.h>

// references (Programming languages C 2011)
// 6.4.4.1 Integer constants
// 6.4.4.2 Floating constants
// 6.5.3 Unary operators
// 6.5.3.4 The sizeof and _Alignof operators
// 6.5.2.2 Function calls
// 7.18 Boolean type and values <stdbool.h>
// 7.21.6 Formatted input/output functions
// J.5.7 Function pointer casts (Common Extensions that are not portable to all implementations)

// references (Dietel and Dietel)
// the _Bool Data Type, pg 135
// the sizeof operator, Section 7.7 pg 292
// format specifiers, Chapter 9, Section 9.4, 9.5.1, 9.10
// function pointers, Section 7.12.1, 7.12.2, pg 311


int main(void)
{
printf("c_datatypes demonstration ");

_Bool b = false;
size_t nBytes = sizeof(_Bool);
printf(" size of _Bool: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof b;
printf("size of the variable 'b': %zu byte(s) ", nBytes);
printf("value of the variable 'b': %d ", b);

char c = 'a';
nBytes = sizeof(char);
printf(" size of char: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof c;
printf("size of the variable 'c': %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
printf("value of the variable 'c': '%c' (0%02o oct) (%d dec) (0x%02x hex) ", c, c, c, c);

int i = 123;
nBytes = sizeof(int);
printf(" size of int: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof i;
printf("size of the variable 'i': %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
printf("value of the variable 'i': %d ", i);

long l = 123;
nBytes = sizeof(long);
printf(" size of long: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof l;
printf("size of the variable 'l': %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
printf("value of the variable 'l': %ld ", l);

size_t st = 123456;
nBytes = sizeof(size_t);
printf(" size of size_t: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof st;
printf("size of the variable 'st': %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
printf("value of the variable 'st': %zu ", st);

uintptr_t uip = 123456789;
nBytes = sizeof(uintptr_t);
printf(" size of uintptr_t: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof uip;
printf("size of the variable 'ip': %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
printf("value of the variable 'uip': %" PRIxPTR" ", uip);

long long ll = 123;
nBytes = sizeof(long long);
printf(" size of long long: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof ll;
printf("size of the variable 'll': %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
printf("value of the variable 'll': %lld ", ll);

float f = 123.12302f;
nBytes = sizeof(float);
printf(" size of float: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof f;
printf("size of the variable 'f': %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
printf("value of the variable 'f': %.7f ", f);

double d = 123.12345;
nBytes = sizeof(double);
printf(" size of double: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof d;
printf("size of the variable 'd': %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
printf("value of the variable 'd': %.7lf ", d);

long double ld = 1234.123456;
nBytes = sizeof(long double);
printf(" size of long double: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof ld;
printf("size of the variable 'ld': %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
printf("value of the variable 'ld': %.7Lf ", ld);

void *pv = (void *)0x1000200012345678;
nBytes = sizeof(void *);
printf(" size of void * pointer: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof pv;
printf("size of the variable 'pv': %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
printf("value of the variable 'pv': %p ", pv);

return 0;
}

1. Your modified source code that includes: a. the header with your name and the assignment,

b. the output for each of the noted datatypes (I’ve removed the function pointer from this assignment – we will cover that in a later assignment)

c. the footer with the program completion status 2. the makefile that you used to build the executable file

3. a screen shot of the output, similar to the sample shown below

CEL VS2015 x64 Native Tools Command Prompt c datatypes demonstration Kyour name goes here CSC-250 Programming Assignment 01, due date: 30Jan 2017 size of Bool: 1 byte size of the variable 'b 1 byte (s) value of the variable 'b 0 size of char: 1 byte size of the variable 'c': 1 byte value of the variable 'c': 'a' (0141 oct) (97 dec) (0x61 hex) size of int: 4 bytes size of the variable 'i': 4 bytes value of the variable 'i' 123 size of long: 4 bytes size of the variable 'l': 4 bytes value of the variable 'l': 123 size of size t 8 bytes size of the variable 'st' 8 bytes value of the variable 'st' 123456 size of uintptr t 8 bytes size of the variable 'ip': 8 bytes value of the variable 'uip' 75bcd15 size of long long: 8 bytes size of the variable '11 8 bytes value of the variable 'll': 123 size of float: 4 bytes size of the variable 'f 4 bytes value of the variable 'f': 123.1230164 size of double: 8 bytes size of the variable 'd 8 bytes value of the variable 'd': 123.1234500 size of long double: 8 bytes size of the variable 'ld 8 bytes value of the variable 'ld 1234.1234560 size of void pointer 8 bytes size of the variable pv 8 bytes value of the variable pv 1000200012345678 Program completion status success Kyour name goes here C: Depot RLFDepot Roy Fine School Dakota CSC250WHW Projects Project 01 s.

Explanation / Answer

makefile -----

cheggProgram: cheggProgram.c
   cc -o cheggProgram cheggProgram.c

cheggProgram.c -------

//
// c-datatypes.c
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <inttypes.h>
// references (Programming languages C 2011)
// 6.4.4.1 Integer constants
// 6.4.4.2 Floating constants
// 6.5.3 Unary operators
// 6.5.3.4 The sizeof and _Alignof operators
// 6.5.2.2 Function calls
// 7.18 Boolean type and values <stdbool.h>
// 7.21.6 Formatted input/output functions
// J.5.7 Function pointer casts (Common Extensions that are not portable to all implementations)
// references (Dietel and Dietel)
// the _Bool Data Type, pg 135
// the sizeof operator, Section 7.7 pg 292
// format specifiers, Chapter 9, Section 9.4, 9.5.1, 9.10
// function pointers, Section 7.12.1, 7.12.2, pg 311

int main(void)
{
printf(" c_datatypes demonstration <<Replace with your name>> CSC-250 Programming Assignment 01, due date:30JAN 2017 ");
_Bool b = false;
size_t nBytes = sizeof(_Bool);
printf(" size of _Bool: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof b;
printf("size of the variable 'b': %zu byte(s) ", nBytes);
printf("value of the variable 'b': %d ", b);
char c = 'a';
nBytes = sizeof(char);
printf(" size of char: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof c;
printf("size of the variable 'c': %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
printf("value of the variable 'c': '%c' (0%02o oct) (%d dec) (0x%02x hex) ", c, c, c, c);
int i = 123;
nBytes = sizeof(int);
printf(" size of int: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof i;
printf("size of the variable 'i': %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
printf("value of the variable 'i': %d ", i);
long l = 123;
nBytes = sizeof(long);
printf(" size of long: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof l;
printf("size of the variable 'l': %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
printf("value of the variable 'l': %ld ", l);
size_t st = 123456;
nBytes = sizeof(size_t);
printf(" size of size_t: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof st;
printf("size of the variable 'st': %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
printf("value of the variable 'st': %zu ", st);
uintptr_t uip = 123456789;
nBytes = sizeof(uintptr_t);
printf(" size of uintptr_t: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof uip;
printf("size of the variable 'ip': %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
printf("value of the variable 'uip': %" PRIxPTR" ", uip);
long long ll = 123;
nBytes = sizeof(long long);
printf(" size of long long: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof ll;
printf("size of the variable 'll': %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
printf("value of the variable 'll': %lld ", ll);
float f = 123.12302f;
nBytes = sizeof(float);
printf(" size of float: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof f;
printf("size of the variable 'f': %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
printf("value of the variable 'f': %.7f ", f);
double d = 123.12345;
nBytes = sizeof(double);
printf(" size of double: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof d;
printf("size of the variable 'd': %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
printf("value of the variable 'd': %.7lf ", d);
long double ld = 1234.123456;
nBytes = sizeof(long double);
printf(" size of long double: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof ld;
printf("size of the variable 'ld': %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
printf("value of the variable 'ld': %.7Lf ", ld);
void *pv = (void *)0x1000200012345678;
nBytes = sizeof(void *);
printf(" size of void * pointer: %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
nBytes = sizeof pv;
printf("size of the variable 'pv': %zu %s ", nBytes, nBytes>1 ? "bytes" : "byte");
printf("value of the variable 'pv': %p ", pv);
return (puts(" Program completion status: success <<Replace with your name>> "));
}