Docsity

computer fundamental C/C++ code, Summaries of Computer Fundamentals

Partial preview of the text

Download computer fundamental C/C++ code and more Summaries Computer Fundamentals in PDF only on Docsity!

CS

Computing Fundamentals

Lecture 1

Why to learn programming?

  • It’s fun
  • You cannot become an engineer without this knowledge
  • Used in many coming courses
  • You’ll use it in your job

Programming

  • Computers are dumb devices that perform only the tasks applied by the user

A Computer Model

  • Computers execute programs
    • Programs are sequence of instructions
    • Instructions are in a language

the computer understands

Important notes

C programming language has the following characteristics:

  • Case sensitive.
  • End each statement with a semicolon except comments.
  • Starting point identified by main().
  • Braces {} signify the begin and end of the program.

Our first program

//our First program in C #include //main function: begins program execution int main() { printf("First cs116 program \n"); return 0; /*indicate end of the main function followed by closing curly bracket */ } First cs116 program

Our first program (cont.)

  • Lines beginning with # are processed before the program is compiled.
  • #include is a directive to the C preprocessor. tells the preprocessor to include the contents of the standard input/output header () in the program.
  • This header contains information used by the compiler when compiling calls to standard input/output library functions such as printf.
  • int main() is a part of every C program.
  • The parentheses after main indicate that a building block called a function.

Our first program (cont.)

  • return 0;
    • Labels the completion of execution of main ,
    • Returns to the system a status value of 0 (You can use any integer here)
    • Zero is used by convention to indicate that the program completed successfully
  • printf();
    • A function that prints what inside the parentheses.

Escape Sequences (cont.)

Sequence Function Description

\n Newline Moves the cursor to the beginning ofthe next

line.

\t Tab character Moves the cursor to the next horizontaltab stop.

" Double quote Used to print double quotes within astring.

' Single quote Used to print single quotes within acharacter

constant.

\ Backslash Used to print a backslash.

\b Backspace Moves the cursor one position to theleft.

\r Carriage

return

Moves the cursor to the beginning ofthe current

line.

Example

#include int main() { printf("Hello, World!\n"); printf("This is a tab\tseparated\toutput.\n"); printf("He said, "Hello there!"\n""); printf("This is a single quote: '\n "); printf("This is a backslash: \\n "); printf("This sentence will\b go back one space.\n"); printf(" This is a return example.\rOverwritten text.\n"); return 0; }

Exercise

  • Write a program that Show the Following Output: