H typedef struct unsigned int unsigned int rational

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: = dob.day)) age = today.year - dob.year else age = today.year - dob.year - 1 printf("Age = %d\n", age) return 0 } CSC 1500 { Lecture 11 11 Structures as function arguments #include <stdio.h> typedef struct { unsigned int unsigned int } Rational num den float rationalToReal(Rational local_rat_copy) { return ((float) local_rat_copy.num / local_rat_copy.den) } int main(void) { Rational rat={3, 4} printf("float=%.2f\n", rationalToReal(rat)) return 0 } float=0.75 Call-by-value is being used when structures are passed as function arguments. That is, a copy of the struct will be made in rationalToReal(). CSC 1500 { Lecture 11 12 Structures as function return values #include <stdio.h> typedef struct { unsigned int unsigned int } Rational num den Rational rationalCreate(unsigned int num, unsigned int den) { Rational rat unsigned int gcd gcd = hcf(nu...
View Full Document

Ask a homework question - tutors are online