Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Prototype-Computer Fundamentals-Lecture Slides, Slides of Computer Fundamentals

The course covers important and advance elements of C and C plus plus programming language. This course provides the student with the skills required to design, code, and test and execute programs of simple to intermediate complexity. It includes: Function, Prototypes, Parameters, Return, Type, Data, Conversions, Header, Files, Reference

Typology: Slides

2011/2012

Uploaded on 07/31/2012

karthik
karthik 🇮🇳

4.6

(16)

95 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
.
5.6 Function Prototypes
Function prototype
Function name
Parameters – what the function takes in
Return type data type function returns (default int)
Used to validate functions
Prototype only needed if function definition comes after use
in program
The function with the prototype
int maximum( int x, int y, int z );
Takes in 3 ints
Returns an int
Promotion rules and conversions
Converting to lower types can lead to errors
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Prototype-Computer Fundamentals-Lecture Slides and more Slides Computer Fundamentals in PDF only on Docsity!

5.6 Function Prototypes

• Function prototype

– Function name

– Parameters – what the function takes in

– Return type – data type function returns (default int)

– Used to validate functions

– Prototype only needed if function definition comes after use

in program

– The function with the prototype

int maximum( int x, int y, int z );

• Takes in 3 ints

• Returns an int

• Promotion rules and conversions

– Converting to lower types can lead to errors

5.6 Function Prototypes

5.7 Header Files

5.8 Calling Functions: Call by Value and

Call by Reference

• Call by value

– Copy of argument passed to function

– Changes in function do not effect original

– Use when function does not need to modify argument

• Avoids accidental changes

• Call by reference

– Passes original argument

– Changes in function effect original

– Only used with trusted functions

• For now, we focus on call by value

5.9 Random Number Generation

• srand function

– <stdlib.h>

– Takes an integer seed and jumps to that location in its

"random" sequence

srand( seed );

– srand( time( NULL ) );/*load <time.h> */

• time( NULL )

– Returns the time at which the program was compiled in

seconds

– “Randomizes" the seed

Outline

fig05_07.c

Outline

fig05_08.c (Part 1

of 3)

Outline

fig05_08.c (Part 2

of 3)

Outline

fig05_09.c (Part 1

of 2)

Outline

fig05_09.c (Part 2

of 2)

Enter seed: 67 Program Output

Enter seed: 867 2 4 6 1 6 1 1 3 6 2 Enter seed: 67 6 1 4 6 2 1 6 1 6 4