IT 3210 - C programming language

0.0(0)
studied byStudied by 0 people
0.0(0)
call with kaiCall with Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/60

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 11:51 PM on 1/20/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

61 Terms

1
New cards

Algorithm

Set of instructions specifying the steps required to accomplish a task

2
New cards

Components of an algorithm

  1. Variables and values

  2. Instructions:

  • Sequences

  • Selections

  • Iterations

  • Procedures

3
New cards

(computer) Program

A sequence of instructions aims at solving a specific task

→ Instruction is carried out one after the other, none carried out when the previous isn’t accomplished

4
New cards

Interpreted & compiled language

  • Interpreted: translated during execution

  • Compiled: translated before execution

5
New cards

Values

Represent quantities/ amounts/ measurements

6
New cards

Variables (definition) 

Containers/ places to store values

→ Can be restricted to contain a specific type of value

7
New cards

Sequence structure

Series of instructions to be carried out one after the other

8
New cards

Selection

An instruction that decides which of two possible sequences is executed

→ Based on a condition (true/false)

  • if …

  • then …

  • else …

9
New cards

Iteration

Repeat an instruction while/ until some true or false condition occurs.

→ Two kinds of iteration: Test the condition each time before/ after repeating the instruction

10
New cards

Procedure

A series of instructions with a name

→ divide a program into smaller parts with different names

11
New cards

C Language Structure

• #include <stdio.h> → To declare using the standard I/O library

• int main() → To declare the main() function → only one

• { … } → The syntax to open and close a block of codes.

• return 0; → Stop the program

12
New cards

Syntax

  • Keywords: reserved words for specific meaning

  • User’s names: defined by user to specify a variable, a function

  • Specific characters: represent expressions in a program and make it have structure

13
New cards

Common used characters

  • {…} create a block of instructions

  • “…” create a string to display

  • /* … */ create a block of comment in the program

  • ; End of an instruction

  • other characters for formulas such as +, -, *, /, (),

14
New cards

Identifier

When declare a variable/ procedure

15
New cards

Variable

  • has a name (identifier)

  • has types

  • declared at the beginning of a function: <data type> <variable list>; → Assignment = puts a specified value into a specified variable

16
New cards

Basic data types

• char

• short

• int

• long

• float

• double

17
New cards

Strings

Groups of char form strings

→ must be enclosed by double quote “ ”

18
New cards

Logic

every number give also a boolean value

• 0 for false

• 1 for true

19
New cards

Const declaration

A variable declaration with the prefix const indicates that the value of that variable never changes in the program.

20
New cards

Data input/ ouput

  • printf()

  • scanf()

21
New cards

Formatting with printf

specify the field width by following:

% [-] [fwidth] [.p] X

• [fwidth] the field width

• [-] left justified

• [.p] the number of decimal places/ how many characters are to be printed

22
New cards

Expressions

  • Combine values using operators, function calls

  • Return a value of a known type 

23
New cards

Operator

Take values & do something to produce a result 

24
New cards

Operand

Operated upon by an operator

25
New cards

Arithmetic operators

  • + (unary plus)

  • - (unary minus)

  • + (addition)

  • - (subtraction)

  • * (multiplication)

  • / (division or quotient)

  • % (modulus or remainder)

26
New cards

Comparison operators

• < (less than)

• <= (less than or equal)

• > (greater than)

• >= (greater than or equal)

• == (equal)

• != (in-equal)

27
New cards

Logic

  • Have 2 values: true (1) ; false (0)

  • Create the selection of conditions/ the loop for an algorithm

28
New cards

Logic operators

• && (and)

• || (or)

• ! (not)

• comparison (==, !=, <, >, <=, >=)

29
New cards

Bit operators

  • & (and bit)

  • | (or bit)

  • ~ (negation)

  • >> (shift right)

  • << (shift left)

30
New cards

Short-circuiting

A complex Boolean expression is only evaluated as far as necessary

31
New cards

Extend assignment operators

  • +=

  • -=

  • *=

  • /=

  • %=

32
New cards

Increment, decrement operators

  • ++ is the increment operator

  • -- is the decrement operator

→ Two ways of writing: prefix (++i) and suffix (i++):

  • Prefix return value after adding 1

  • Suffix return value before adding 1

  • In both cases, value of i increases by 1

33
New cards

Conditional Expressions

<Condition> ? <Expression 1> : <Expression 2>

34
New cards

Casting data type

int a;

float f;

a = (int) f;

35
New cards

Precedences

• Unary operators (!, -)

• Multiply, divide (*, /, %)

• Addition, subtraction (+, -)

• Comparison 1 (<, <=, >, >=)

• Comparison 2 (==, !=)

• And (&&)

• Or (||)

• Assignment (=)

36
New cards

if statement

if ( expression )

statement

37
New cards

Statements

lines of instructions in programs ending with a semicolon (;).

• A compound statement/ block: series of statements surrounded by braces.

• An empty statement: a single semicolon.

38
New cards

else statement

if ( expression )

statement1

else statement2

  • only occur after an if statement

  • only executed when the if block does not execute

39
New cards

Cascading if (else-if)

if (expr1)

statement1

else if (expr2)

statement2

else if (expr3)

statement3

else

statement4

  • At most only one block will be executed

  • Choose one among several conditions

40
New cards

switch statement

switch (integer value)

{

case 1: statement1;

break; /* optional line */

case 2: statement2;

break; /* optional line */

....

default: default statement;

break; /* optional line */

}

  • The expression in the parentheses is evaluated

  • Check to see whether the result matches any constants labelled with case

  • A match is made → execution start after that case statement → carry on until the closing brace } / break statement

  • Default case are executed for all cases not specifically listed

41
New cards

Using break

All following statements are carried out until a break statement

→ break is a way of jumping straight out of the switch block

42
New cards

Loop

Repeat statement(s)

→ Provide versatile manipulation:

  • number of repetitions

  • range of loops

43
New cards

while loop

while ( condition(s), )

statement(s)

• Execute a statement according to a condition

• Verify the condition at the beginning of the loop

• Stop the loop when the condition is false ( = 0 )

44
New cards

for loop

for ( initialization ; condition ; update )

   statement

  • All components are optional → If the condition is empty, interpreted as true

  • (,) separates elements of a component

45
New cards

do … while statement

do {

statements;

} while ( condition);

→ The loop always executed at least once before the test → determine whether it should continue

46
New cards

Infinitive loops

The loop condition is always true

  • while (1)

  • for (;;)

47
New cards

Break statement

Use in an infinitive loop to terminate the loop

→ for (;;)

if (condition) break;

}

48
New cards

Continue statement

A loop will stop whatever it is doing → go straight to the start of the next loop pass

→ for (…)

{…

if ( condition) continue;

…}

49
New cards

build function

specify

  • function name

  • input parameters

  • type of value returned ( if exists)

  • block of statements executed when function is called → function body

50
New cards

function parameter

local variable of a function whose parameter is determined each function call

→ no parameter → use void

51
New cards

return statement

return a value

→ may have multiple returns → first one encountered terminates the others

52
New cards

function declaration & definition

  • definition: specify all components

  • declaration: specify name, type of parameter, return type → function prototype

53
New cards

global & local variable

  • global: declare outside function → accessed by multiple functions

  • local: declared inside a function → accessed only in that function
    → name conflict → local variable takes precedence

54
New cards

Array

block of variables that have the same datatype → fixed number of elements

55
New cards

Pointers

variable that can store the memory of another

→ format specifier: %p

56
New cards

How to use pointer

  • declare variable pointed to by pointer: int num

  • declare pointer: int *numPtr = NULL;

  • assign reference to pointer: numPtr = &num;

  • dereference pointer: *numPtr = 65;

57
New cards

String processing

  • assignment( copy): strcpy ()

  • concatenation: strcat ()

  • comparison: strcmp ()

  • get strign length: strlen ()

58
New cards

string comparison

strcmp (string1, string2)

→ lexicographically compare

result:

  • = 0 → equal

  • > 0 → string 1 > string 2

  • < 0 → string 1 < string 2

59
New cards

Struct

collection of variables

struct nameOfstruct {

};

→ names of variables inside struct: struct fields/ members

→ access a field: use . → nameOfstruct.variableName

60
New cards

typedef

define new data type name that can be used in variable declaration

61
New cards

input/ output stream

buffered area used for high-level data input, output

→ 3 standard streams:

  • stdin: input

  • stdout: output

  • stderr: error

Explore top flashcards