C Programming Language Fundamentals: Introduction to C Programming, Lecture notes of Computer Science

• C-Language Basics • Standard Input/Output • Built-in Data Types • Variables and Variable Scope • Operators • Branching statements • Loop statements

Typology: Lecture notes

2022/2023

Uploaded on 05/31/2023

juanitojorge
juanitojorge 🇺🇸

1 document

1 / 39

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
System
Fundamentals
Brent C. Munsell
1
C Programming Language
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27

Partial preview of the text

Download C Programming Language Fundamentals: Introduction to C Programming and more Lecture notes Computer Science in PDF only on Docsity!

System

Fundamentals

Brent C. Munsell

1

C Programming Language

Agenda

  • Announcements
  • C-Language Basics
  • Standard Input/Output
  • Built-in Data Types
  • Variables and Variable Scope
  • Operators
  • Branching statements
  • Loop statements

C-Language

Basics

4

Simple Program #include <stdio.h> int main( int argc, char** argv ) { printf("Hello, World!\n"); return 0; }

C comments Identical to Java (Comp 210)! // Comment a single line /* Comment multiple lines */

Software program!

  • Commonly referred as “the compiler” … but much much

more :)

Important flags used by GCC:

    • g: produce debug information (used by GDB/valgrind)
    • Werror: treat all warnings as errors (this is our default)
    • Wall: enable all compiler warnings
    • o : name of the executable file Example: gcc – g - Werror - Wall first.c - o first 8 GNU Compiler Collection (GCC)

Standard

Input/Output

10 read and write

Standard Output (stdout)

#include <stdio.h>

int main( int argc, char** argv ) {

printf(”%s!\n”, “Hello World”);

return 0;

  • printf function and format specifiers
    • Displays characters in terminal (stdout)
  • Same as Java version (System.out.printf) and the documented format specifiers. Terminal Keyboard (stdin) Display (stdout) Standard Input/Output Library

Built-in Data

Types

13 32 - bit System

Typical Types (Size and Range) Type Storage size Value range char 1 byte - 128 to 127 or 0 to 255 (system dependent) unsigned char 1 byte 0 to 255 signed char 1 byte - 128 to 127 int 4 bytes - 2,147,483,648 to 2,147,483, unsigned int 4 bytes 0 to 4,294,967, short 2 bytes - 32,768 to 32, unsigned short 2 bytes 0 to 65, long 8 bytes - 9223372036854775808 to 9223372036854775807 unsigned long 8 bytes 0 to 18446744073709551615

Variables

16 Declaration and Names

Variable declaration data type variable name; // without initialization e.g., int a;

  • or- data type variable name = value; // initialization e.g., int a = 10; Identical to Java

Variable

Scope

19 global and local

Global Variable unsigned int x = 10; int main() { printf(”x = %d\n”, x ); func(); return 0; } void func() { printf(”x = %d\n”, x ); } 20 Global Variable