You are on page 1of 134

THE ORIGIN OF C

BCPL (Martin Richards)


Language B (Ken Thompson) C (Dennis Ritchie) early 1970s
Bell Laboratories

THE ORIGIN OF C
ANSI established a committee in the beginning of summer, 1983 to create an ANSI Standard for C Language
The standard was finally adopted in 1990. Turbo C fully implements the resulting ANSI standard for C DEC-PDP11 was the 1st program created using C that uses the UNIX Operating System.

* BCPL = Binary Coded Programming Language


*ANSI = American National Standard Institute *ASCII = American Standard Code for Information Interchange

MIDDLE-LEVEL LANGUAGE
C is often called a middle-level language, meaning it combines elements of high-level language with the functionality of assembly language.

HIGH-LEVEL LANGUAGES:
ADA (US Dept. of Defense) MODULA-2 (Niklaus Wirth, 1980) PASCAL (named after Blaise Pascal) FORTRAN BASIC COBOL

HIGH-LEVEL LANGUAGES:
PASCAL (named after Blaise Pascal)
Procedural programming language that encourages programmers to write well-structured, modular programs that take advantage of modern control structures and lack of spaghetti code

HIGH-LEVEL LANGUAGES:
FORTRAN = Formula Translation
Enables programmers to describe and solve complex mathematical calculations

HIGH-LEVEL LANGUAGES:
BASIC = Beginners All-Purpose Symbolic Instruction Code
Developed in 1964; a procedural language that tells the computer what to do step-by-step

HIGH-LEVEL LANGUAGES:
COBOL = Common Business Oriented Language
Developed/designed business applications for

MIDDLE-LEVEL LANGUAGES:
C FORTH = Fourth Generation
Charles Moore, 1970

MACRO-ASSEMBLY LOWEST LEVEL LANGUAGE ASSEMBLY LANGUAGE

32 Keywords as Defined by the ANSI Standard


auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while

The Turbo C Extended Keywords


asm _ss interrupt _cs cdecl near _ds far pascal

The General Form of a C Program


global declarations main () { local variables statement sequence } f1 () { local variables statement sequence } f2 () local variables statement sequence
} . . . fN () { local variables statement sequence }

QUIZ
I. Identify the person who developed the following: 1. BCPL 2. C 3. Language B 4. MODULA-2 5. FORTH II. Write the meaning of the ff. acronyms: 6. BASIC 7. COBOL 8. ASCII 9. FORTRAN 10. BCPL

ANSWERS
I. Identify the person who developed the following: 1. BCPL - Martin Richards 2. C Dennis Ritchie 3. Language B Ken Thompson II. Write the meaning of the ff. acronyms: 6. BASIC Beginners All-Purpose Symbolic Instruction Code 7. COBOL Common Business Oriented Language 8. ASCII American Standard Code for Information Interchange 9. FORTRAN Formula Translation 10. BCPL- Binary Coded Programming Language

4. MODULA-2 Niklaus Wirth


5. FORTH Charles Moore

Identifier Names
IDENTIFIERS
names used to reference variables, functions, labels, and various other userdefined objects can vary from 1 to 32 characters the first character must be a letter or an underscore

IDENTIFIERS
Correct Incorrect

weee lalala23 for_ty

17weee lalala!23 forty

Data Types
character
integer

floating point
double floating point

valueless

char
used ASCII characters or any 8-bit quantity from values -128 to 127 (but only 0 to 127 are used) ex. char ch; ch = e; *it is also possible to have the type unsigned char

Control characters i.e. non printable characters are put into programs by using a backslash \ and a special character or number. The characters and their meanings are:
\b backspace BS
\f form feed FF (also clear screen) \n new line NL (like pressing return or enter) \r carriage return CR (cursor to start of line) \t horizontal tab HT \v vertical tab (not all versions)

\ double quotes (not all versions)


\ single quote character \\ - backslash character \0 null \a alert \o octal constant \x hexadecimal constant

int
used to hold integer quantities
ex. :

int i, j;
i = j = 0;

int x = 25;

float
used to hold real numbers
ex. : float x, y, z; x = 0.1; y = 2.317; z = 0;

double
used to hold real numbers
ex. : double big; small; big = 2.36E208; small = 3.2E 300;

void
declares explicitly a function as a returning no value
declares explicitly a function as having no parameters creates generic pointers

MODIFIERS
alter the meaning of the base type to fit the needs of the various situations more precisely signed, unsigned, long, short may be applied to character and integer base types
*long may also be applied to double

Access Modifiers
control the ways in which variables may be accessed or modified
const may not be changed during execution by your program ex. : const int a; const int count = 100;

Access Modifiers
control the ways in which variables may be accessed or modified
volatile tells the compiler that a variables value can be changed in ways not explicitly specified by the program ex. : const volatile unsigned char *port=0x30;

Declaration of Variables
all variables must be declared before they are used general form of a declaration: type variable_list; type valid C data type variable_list may consist of one or more identifier names with comma separators

Examples:
int a, b, c;

unsigned int er;


short int be; double hi, bye, toink;

Local Variables
declared inside a function may be referred to as automatic variables

can be referenced only by the statements that are inside the block in which the variables are declared

Formal Parameters
If a function is to use arguments, then it must declare variables that will accept the values of the arguments. behave like any other variables inside the function

Global Variables
known throughout the entire program and may be used by any piece of code hold their values during the entire execution of the program created by declaring them outside of any function

STORAGE CLASS SPECIFIERS


tell the compiler how the variable that follows should be stored precedes the rest of the variable declarations general form: storage_specifier type var_name;

STORAGE CLASS SPECIFIERS


extern tells the compiler that the following variable types and name have been declared elsewhere static permanent variables within their own function call or file

STORAGE CLASS SPECIFIERS


static permanent variables within their own function call or file static local variable causes the compiler to create permanent storage for it in much the same way that it does for a global variable; remains known only to the block in which it is declared

STORAGE CLASS SPECIFIERS


static permanent variables within their own function call or file static global variable instructs compiler to create a global variable that is known only to the file where the static global variable is declared

STORAGE CLASS SPECIFIERS


register requests Turbo C to store a variable declared with this modifier in a manner that allows the fastest access time possible; may be applied to local variables and formal parameters in a function but not to global variables auto

VARIABLE INITIALIZATION
giving variables in C a value at the time they are declared by placing an equal sign and a constant after a variable name general form: type variable_name = constant; ex.: int x = 1;

II. Match column A with column B


A B 6. may not be changed during execution by your program a. const b. type variable_name 7. tells the compiler that a variables = constant; value can be changed in ways c. volatile not explicitly specified by the program d. register e. type variable_list; 8. general form of a declaration f. global variables 9. variables declared inside a function g. local variables 10. variables used if a function is is h. formal parameters to use arguments i. extern 11. variables known throughout the j. static entire program and may be used by any piece of code 12. tells the compiler that the following variable types and name have been declared elsewhere

QUIZ I. Identification
1. names used to reference variables 2. used to hold integer quantities 3. 3-4. used to hold real numbers

5. declares explicitly a function as having no parameters

13. permanent variables within their own function call or file


14. requests Turbo C to store a variable declared with this modifier in a manner that allows the fastest access time possible 15. general form of variable initialization

II. Match column A with column B


A B a.6. may not be changed during execution by your program a. const b. type variable_name c.7. tells the compiler that a = constant; variables value can be changed in ways not explicitly specified c. volatile by the program d. register e. type variable_list; e.8. general form of a declaration f. global variables g.9. variables declared inside a function g. local variables h.10. variables used if a function is is h. formal parameters to use arguments i. extern f.11. variables known throughout the j. static entire program and may be used by any piece of code i.12. tells the compiler that the following variable types and name have been declared elsewhere

QUIZ I. Identification
1. names used to reference variables identifiers 2. used to hold integer quantities int 3-4. used to hold real numbers float, double 5. declares explicitly a function as having no parameters - void

j.13. permanent variables within their own function call or file


d.14. requests Turbo C to store a variable declared with this modifier in a manner that allows the fastest access time possible b.15. general form of variable initialization

OPERATORS
symbols that tell the compiler to perform specific mathematical or logical manipulations Assignment Operators
general form of assignment statement: variable_name = expression; ex. : x = a+b;

Special Assignment Operators:


+= -= *= /= %= add assign subtract assign multiply assign divide assign (double and int types) remainder assign (int type only)

ARITHMETIC OPERATORS
Operator Action subtraction + addition * multiplication / division % modulus division -decrement ++ increment

RELATIONAL and LOGICAL OPERATORS


relational refers to relationship values can have with one another logical refers to the ways these relationships can be connected together using the rules of formal logic true = 1; false = 0

RELATIONAL OPERATORS
Operator Action > greater than >= greater than equal to less than < less than equal to <= equal == not equal !=

LOGICAL OPERATORS
Operator && || !
Action AND OR NOT

LOGICAL OPERATORS
p 0 0 1 1 q 0 1 1 0 p&&q 0 0 1 0 p||q 0 1 1 1 !q 1 1 0 0

BITWISE OPERATORS
the testing, setting, or shifting of the actual bits in a byte or word *shift operators >> and << move all bits in a variable to the right or left as specified *ones compliment operator ~ will reverse the state of each bit in the specified variable

BITWISE OPERATORS
Operator Action & AND OR | ^ EXCLUSIVE OR (XOR) Ones Compliment ~ Shift right >> Shift left <<

BITWISE OPERATORS
p 0 0 1 1 q 0 1 1 0 p&&q 0 0 1 0 p||q 0 1 1 1 !q 1 1 0 0

? OPERATOR
ternary operator replace certain statement of if-then-else form general form: Exp1 ? Exp2 : Exp3

& and * POINTER OPERATORS


pointer memory address of a variable & - unary operator that returns memory address of its operand * - complement of &

QUIZ
ENUMERATION: ANSWERS:

1-5. Special Assignment Operators


6-12. Arithmetic Operators

1-5. += , -= , *=, /= , %=
6-12. - , + , * , / , & , -- , ++ 13-18. > , >=, < , <=, == , !=

13-18. Relational Operators

19-21. && , || , !
19-21. Logical Operators 22-28. & , | , ^ , ~ , >> , << 22-27. Bitwise Operators

Rules for Writing a C Program


1) The header files should be declared at the starting of the program in each line. ex.) #include <stdio.h> 2) Every program should contain "main" statement with return-type void. By default it takes "int" as the return-type. It is the main function where the compiler starts executing the program. 3) The block of statements should be enclosed within '{'

Rules for Writing a C Program


4) Every statement should be terminated with semicolon (;)
5) The variable should be declared at the starting of the statement. 6) C is a case sensitive so the program should be written in lower case letters except some keywords, class name etc.

Formatted Input and Output Statement


printf()
used to display the string or to display the contents in the output screen Syntax: printf(string /formatted string,var1,var2..); Example: printf(it is c-language); printf(the value is: %d,a);

Formatted Input and Output Statement


scanf()
used to accept the contents into the variable until it founds enter(return) key or space symbol Syntax: scanf(formatted string,&var1,&var2.); Example: scanf(%d,&a); scanf(%d%d%d,&a,&b,&c); scanf(%c,&ch);

Sample Program
To display text:
#include<stdio.h> main() { printf(Hello World!);

Sample Program
To display inputted number: #include<stdio.h> main() {

int a; printf(enter a number); scanf(%d, &a); printf(the inputed number is %d, a); }

Conditional Statement
if statement
if (expression) { statement sequence } else { statement sequence }

Conditional Statement
sample program using if statement:
#include<stdio.h> main() { int x = 123; int y; printf(enter your guess); scanf(%d, &y); if (y==x) {printf(Right);} }

Conditional Statement
sample program using if-else statement:
#include<stdio.h> main() { int x = 123; int y; printf(enter your guess); scanf(%d, &y); if (y==x) {printf(Right);} else { printf(Wrong); } }

Conditional Statement
nested if if statement that is the object of either an if or else
#include <stdio.h> main(){ int x=123, y; printf(Enter your guess: ); scanf(%d, &y); if (y!=x)
{ if(y>x) printf(..too high..); else printf(..too low..);} else printf(Its correct!); }

Conditional Statement
if-else-if ladder - common programming construct
if (expression) statements; else if (expression) statements; else if (expression) statements; . . . else statement;

Conditional Statement
sample program using if-else-if ladder:
#include<stdio.h> main() { int x = 123; int y; printf(enter your guess); scanf(%d, &y); if (y==x) {printf(Right);} else if (y>x) { printf(Wrong, too high); } else printf(Too Low); }

Conditional Statement
? alternative - ? operator can be used to replace if/else statement called ternary operator because it requires 3 operands Exp1 ? Exp2 : Exp3

Conditional Statement
sample program using ? alternative:
#include<stdio.h> main() { int x = 123; int y; printf(enter your guess); scanf(%d, &y); if (y==x) {printf(Right);} else y > x ? printf(too high) : printf(too low); }

Conditional Statement
Switch statement often used to process keyboard commands such as menu selection switch (variable) { case constant1: statement sequencebreak; case constant2:statement sequencebreak; . . . default:statement sequence; }

Conditional Statement
the default statement is executed if no matches are found; if not present, no action takes place if all matches fail break statement is optional switch differs from if in that switch can only test for equality whereas the if can evaluate a relational or logical expression no two case constants in the same switch can have identical values; a switch statement enclosed by an outer switch may have constants that the same if character constants are used in the switch, they are automatically converted to their integer values

Conditional Statement
sample program using switch statement:
#include <stdio.h> const int RED = 1; const int GREEN = 2; const int BLUE = 3; void main(){ int color = 1; printf("Enter an integer to choose a color(red=1,green=2,blue=3):\n"); scanf("%d",&color);

switch(color){ case RED: printf("you chose red color\n"); break; case GREEN:printf("you chose green color\n"); break; case BLUE:printf("you chose blue color\n"); break; default:printf("you did not choose any color\n"); } }

Conditional Statement
Nested Switch Statements switch(x) { case 1: switch(y) { case 0: printf(Typed something.\n"); break; case 1: process(x,y); } break; case 2: }

LOOPS
provide a way to repeat commands and control how many times they are repeated while loop - executes a statement repeatedly as long as the controlling expression is true Syntax: while(condition) { statement(s); }

LOOPS
Sample Program (while loop)
#include <stdio.h> main () { int i = 0; while (i<10) { printf ("\n%d", i); i++; } }

LOOPS
Sample Program (while loop) OUTPUT: 0 1 2 3 4 5 6 7 8 9

LOOPS
for loop similar to while but written differently; often used to process lists such as a range of numbers
Syntax: for(expression1; expression2; expression3) { statement(s); }

LOOPS
expression1 initializes variables expression2 conditional expression, as long as this condition is true, the loop will keep executing expression3 modifier which may be simple increment of a variable

LOOPS
Sample Program (for loop)
#include <stdio.h> main () { int i; for (i=0; i<=10; i++) { printf (hello %d\n, i); } }

LOOPS
Sample Program (for loop) OUTPUT: hello 0 hello 1 hello 2 hello 3 hello 4 hello 5 hello 6 hello 7 hello 8 hello 9 hello 10

LOOPS
do/while loop allows you to execute code block in loop body at least once
Syntax: do { statement(s); } while(condition);

LOOPS
Sample Program (do/while loop)
#include <stdio.h> main () { int i = 0; do { printf ("\n%d", i); i++; } while (i<10); }

LOOPS
Sample Program (do/while loop) OUTPUT: 0 1 2 3 4 5 6 7 8 9

LOOPS
break terminate a case in a switch statement; force immediate termination of a loop example: #include <stdio.h> main () { int i; for (i=0; i<=10; i++) { printf (hello%d\n, i); if (i==5) break; } }

LOOPS
OUTPUT:
hello0 hello1 hello2 hello3 hello4 hello5

QUIZ
1-3. general format for if-else-if ladder 4-5. general format for ternary operator 6-10. Make a program to find the biggest of 3 inputted numbers. 11-15. Trace the output of the ff. program:
#include<stdio.h> main() {int i,j; for(i=1;i<=5;i++) { for(j=1;j<=i;j++) { printf("%d",i); }printf("\n"); } }

Answers: 1-3. if (expression) statements; else if (expression) statements; else if (expression) statements; . . . else statement; 4-5. Exp1 ? Exp2 : Exp3

QUIZ
1-3. general format for if-else-if ladder 4-5. general format for ternary operator 6-10. Make a program to find the biggest of 3 inputted numbers. 11-15. Trace the output of the ff. program:
#include<stdio.h> main() {int i,j; for(i=1;i<=5;i++) { for(j=1;j<=i;j++) { printf("%d",i); }printf("\n"); } } 6-10. #include<stdio.h>main(){ int a,b,c; printf("enter three numbers"); scanf("%d%d%d",&a,&b,&c);if (a>b && a>c){printf("the biggest number is:%d",a);} else if(b>a && b>c) {printf(" the biggest number is:%d",b);} else{printf(" the biggest number is:%d",c);} }

QUIZ
1-3. general format for if-else-if ladder 4-5. general format for ternary operator 6-10. Make a program to find the biggest of 3 inputted numbers. 11-15. Trace the output of the ff. program:
#include<stdio.h> main() {int i,j; for(i=1;i<=5;i++) { for(j=1;j<=i;j++) { printf("%d",i); }printf("\n"); } }

11-15. 1 22 333 4444 55555

STRINGS
Strings are stored in memory as ASCII codes of characters that make up the string appended with \0(ASCII value of null)
The last character is the null character having ASCII value zero.

INITIALIZING STRINGS
general format:
char string_name[size]; example: char month[10]; char address[100];

String operations (string.h)


strlen() function - counts and returns the number of characters in a string. The length does not include a null character.
Syntax: n=strlen(string); Where n is an integer variable which receives the value of length of the string.

String operations (string.h)


strcat() function - when you combine two strings, you add the characters of one string to the end of other string. This process is called concatenation. The strcat() function joins 2 strings together. It takes the following form strcat(string1,string2);
string1 & string2 are character arrays. When the function strcat is executed string2 is appended to string1. the string at string2 remains unchanged.

String operations (string.h)


strcmp function compares two strings (case sensitive); returns a zero if 2 strings are equal, or a non zero number if the strings are not the same.
Syntax: strcmp(string1,string2);

String operations (string.h)


strcmpi() function compares two strings but not case sensitive.
Syntax:

strcmpi(string1,string2);

String operations (string.h)


strcpy() function
Syntax: strcpy(string1,string2); strcpy assigns the contents of string2 to string1. string2 may be a character array variable or a string constant.

String operations (string.h)


strlwr() function converts all characters in a string from uppercase to lowercase.
Syntax:

strlwr(string);

String operations (string.h)


strupr() function converts all characters in a string from lower case to uppercase.
Syntax:

strupr(string);

String operations (string.h)


strrev() function reverses the characters in a string
Syntax:

strrev(string);

Sample Program Using Strings


Reading String from the terminal #include<stdio.h> main() { char month[15]; printf (Enter the string); gets (month); printf (The string entered is %s, month); }

QUIZ
1. It is a sequence of characters.
2. General format of declaring a string variable. 3. This function counts and returns the number of characters in a string. 4. This function compares 2 strings but not case sensitive. 5. In this function, you add the characters of one string to the end of other string

QUIZ
6. This function compares two strings (case sensitive)
7. This function converts all characters in a string from uppercase to lowercase. 8. This function converts all characters in a string from lower case to uppercase. 9. This function reverses the characters in a string. 10. This function assigns the contents of one string to another string.

QUIZ
11-15. Write a C program to find the length of the string using strlen() function.
16-20. Write a C program that will concatenate two strings and display the output.

QUIZ
1. It is a sequence of characters. string 2. General format of declaring a string variable. char string_name[size]; 3. This function counts and returns the number of characters in a string. strlen() 4. This function compares 2 strings but not case sensitive. strcmpi() 5. In this function, you add the characters of one string to the end of other string strcat()

QUIZ
6. This function compares two strings (case sensitive) strcmp() 7. This function converts all characters in a string from uppercase to lowercase. strlwr()

8. This function converts all characters in a string from lower case to uppercase. strupr()
9. This function reverses the characters in a string. strrev() 10. This function assigns the contents of one string to another string. strcpy()

QUIZ
11-15. Write a C program to find the length of the string using strlen() function. #include < stdio.h > #include < string.h > void main() { char name[100]; int length; printf(Enter the string); gets(name); length=strlen(name);

printf(\nNumber of characters in the string is=%d,length); }

QUIZ
16-20. Write a C program that will concatenate two strings and display the output. #include < stdio.h > #include < string.h > void main() { char s1[20],s2[20]; printf(Enter the strings); scanf(%s%s,s1,s2); printf(The concatenation of the strings is %s, strcat(s1,s2)); }

QUIZ
16-20. Write a C program that will concatenate two strings and display the output.
OUTPUT: s1 hi s2 world The concatenation of the strings is hiworld

ARRAYS
its type and dimensions must first be declared array elements start with 0 data is entered into an array using loops size: maximum number of elements that can be stored inside an array

ARRAYS
Syntax: type arrayname[size] = {list value}; example: int n[10]; int n[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

Sample Program Using ARRAYS


#include <stdio.h> main() { int age[4]; age[0]=23; age[1]=34; age[2]=65; age[3]=74; printf("%d\n", age[0]); printf("%d\n", age[1]); printf("%d\n", age[2]); printf("%d\n", age[3]); } OUTPUT: 23 34 65 74

MULTIDIMENSIONAL ARRAYS
"arrays of arrays For example, a bidimensional array can be imagined as a bidimensional table made of elements, all of them of a same uniform data type.

MULTIDIMENSIONAL ARRAYS
int array [3][5];
0 0 1 1 2 3 4

MULTIDIMENSIONAL ARRAYS
array [1][2]
0 0 1 1 2 3 4

MULTIDIMENSIONAL ARRAYS
Multidimensional arrays are not limited to two indices (i.e., two dimensions). They can contain as many indices as needed. But be careful! The amount of memory needed for an array rapidly increases with each dimension.

MULTIDIMENSIONAL ARRAYS
Multidimensional arrays are just an abstraction for programmers, since we can obtain the same results with a simple array just by putting a factor between its indices: int jimmy [3][5]; // is equivalent to int jimmy [15]; // (3 * 5 = 15)

Sample Program using 2D ARRAY


Multiplication Table: #include<stdio.h>
#define WIDTH 5 #define HEIGHT 3 int table [HEIGHT][WIDTH]; int n,m; int main ()

for (n=0;n<HEIGHT;n++){ for (m=0;m<WIDTH;m++) { table[n][m]=(n+1)*(m+1); printf("%d\t", table[n][m]); } printf("\n"); } return 0; }

Output:

1 2

2 4

3 6 9

4 8 12

10
3 6

MULTIDIMENSIONAL ARRAYS
We have used "defined constants" (#define) to simplify possible future modifications of the program. For example, in case that we decided to enlarge the array to a height of 4 instead of 3 it could be done simply by changing the line:
#define HEIGHT 3 to: #define HEIGHT 4 with no need to make any other modifications to the program.

MULTIDIMENSIONAL ARRAYS (3D)


conceptual syntax: data_type array_name[s1][s2][s3]; If you want to store values in any 3D array then first point to table number, row number and lastly to column number.

MULTIDIMENSIONAL ARRAYS (3D)

example: int array[2][2][2]; array [1][1][2] = 40;

Sample Program using 3D ARRAY


#include<stdio.h> #include<conio.h> void main(){ int i, j, k; int arr[3][3][3]= { {11, 12, 13}, {14, 15, 16}, {17, 18, 19} }, { {21, 22, 23}, {24, 25, 26}, {27, 28, 29} }, { {31, 32, 33}, { {34, 35, 36}, {37, 38, 39} }, }; clrscr(); printf(":::3D Array Elements:::\n\n"); for(i=0;i<3;i++){ for(j=0;j<3;j++) { for(k=0;k<3;k++) { printf("%d\t",arr[i][j][k]); } printf("\n"); } printf("\n"); } getch(); }

Output:
11 14 17 21 24 27 31 34 37 12 15 18 22 25 28 32 35 38 13 16 19 23 26 29 33 36 39

QUIZ
1. What is the size of the array int ict[25]; ? 2. Array elements start with ___ 3. You enter data into array elements using _____ 4. Syntax of One Dimensional Array 5. Syntax of 3D Array

QUIZ
6. Declare an array w/ array name money, size 25, type int 7. Declare the integer variable twenty with elements 3, 4, and 5 8. Declare a define constant day 8 9. In the array hello[2][4][6] , [6] is the ___? 10. They are known as arrays of arrays.

QUIZ
11. Draw a table of an array for integer variable train[3][4]; 12. Using the memory block allocation in #11 let train[0][1] = 1 13. Using the memory block allocation in #11 let train[3][2] = 20 14. Using the memory block allocation in #11 let train[2][3] = 23 15. Using the memory block allocation in #11 let train[3][4] = 17

QUIZ
16-20. Make a code that will display the following output: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

QUIZ
21-25. Trace the output of the following program: #include<stdio.h> #define WIDTH 5 #define HEIGHT 2 int table[HEIGHT][WIDTH]; int x, y; int z=10; int main(){ for (x=0; x<HEIGHT; x++){ for (y=0; y<WIDTH; y++){ table [x][y] = z; printf("array[%d][%d] = %d\n", x, y, table[x][y]); z+=10; } } }

QUIZ
1. What is the size of the array int ict[25]; ? 25 2. Array elements start with ___ 0 3. You enter data into array elements using _____ loops 4. Syntax of One Dimensional Array type arrayname[size] = {list value}; 5. Syntax of 3D Array data_type array_name[s1][s2][s3];

QUIZ
6. Declare an array w/ array name money, size 25, type int int money[25]; 7. Declare the integer variable twenty with elements 3, 4, and 5 int twenty[3][4][5]; 8. Declare a define constant day 8 #define day 8 9. In the array hello[2][4][6] , [6] is the ___? column number 10. They are known as arrays of arrays. multidimensional arrays

QUIZ : 11-15.
int train [3][4];
0 0 1 1 1 20 17 23 2 3

QUIZ 16-20.
#include<stdio.h> main(){ int table[7][5]; int x, y; int z=0; for (x=0; x<7; x++){ for (y=0; y<5; y++){ table [x][y] = z; printf("%d\t", table[x][y]); z++; } printf("\n"); } }

QUIZ 21-25.
array[0][0] = 10 array[0][1] = 20 array[0][2] = 30 array[0][3] = 40 array[0][4] = 50 array[1][0] = 60 array[1][1] = 70 array[1][2] = 80 array[1][3] = 90 array[1][4] = 100

You might also like