This page is located in archive. Go to the latest version of this course pages. Go the latest version of this page.

Lab03 - Types and arrays


  • Variables
    • Many built-in variables for system tools like RM for rm -f, CC for gcc or CXX for g++

  VAR := $(CC)
  VERSION = $(CXX) --version
  CFLAGS ?= -Wall -Werror
  LIBS += -lm
  define ARR

  • Then we can write our Makefile as

  LIBS += -lm
  OUTNAME := output
  SRC += main.c
	$(CC) $(SRC) -o $(OUTNAME) $(LIBS)

Data types

  • Basic data types
    • _Bool
    • char < short < int < long < long long
    • unsigned char < unsigned short < unsigned < unsigned long
    • float < double < long double
  • Precise data types (defined in <stdint.h>)
    • int8_t
    • int16_t
    • int32_t

Arrays and pointers

  • No checking of the out-of-bound indexing
  • Fixed size known at the compile time

int arr[10];

int n = 5;
char vars[n];

float coeffs[] = {4.2, 0.12, 8.7773};

  • Arrays are passed to functions as pointers


  1. Write a program that will perform a dot product of two vectors (represented as 1D arrays)
  2. Write a program which reads a string with a length given by the user and counts all vowels (a, e, i, o, u) in a separate function. Hint: use function
    char *fgets(char *s, int size, FILE *stream)
  3. Write a program which creates an array with variable length based on the user input. Then it reads the desired number of integers and then outputs their cumulative sum.
  4. Write a program that reads a 5×5 array of integers and then prints the row sums and the column sums.
courses/be5b99cpl/labs/lab03.txt · Last modified: 2022/10/12 11:03 by ulricji1