




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Notes; Class: Introduction to C Programming for Engineers; Subject: Computer Systems Engineering ; University: University of Alaska - Anchorage; Term: Fall 2008;
Typology: Study notes
1 / 8
This page cannot be seen from the preview
Don't miss anything!
The first element of an array is in the 0 th position
So arrays are addressed from 0 to one less than the length of thearray
int nums[10]; char names[20];
Often array sizes are specified in constants that can be used throughoutthe program
To define a constant, use the #define preprocessor directive, which isplaced below the #include statements - NOTE: Preprocessor directives are not C code – it is a symbolic constant that isreplaced with the replacement text by the C preprocessor before the program iscompiled #include <stdio.h> #define SIZE 10 void main() { int numArray[SIZE]; int i; for (i=0; i < SIZE; i++) { numArray[i] = 1; } }
void my_function(int numArr[], int size) { } void main() { int numArray[10]; my_function(numArray, 10); }
srand(time(NULL)); // seeds the rand function
rand() returns a random number between 0 and RAND_MAX,which is defined in stdlib.h to be at least 32767 - 1 + rand() % 6 then gives us a number between 1 and 6, inclusively