Introduction in C

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

Which of the following is NOT a primary reason for learning data structures?

  • To optimize data storage and retrieval.
  • To understand memory usage at a low level.
  • To improve the efficiency of algorithms.
  • To learn the syntax of different programming languages. (correct)

What is the benefit of implementing data structures in C for the CP264 course?

  • It facilitates a deeper understanding of memory management. (correct)
  • Python is not suitable for implementing data structures.
  • C automatically handles memory management.
  • C syntax closely resembles Python.

What is the primary focus of CP264 concerning data structures, compared to CP164?

  • Understanding basic data structure concepts.
  • Implementing high-performance data structures in C. (correct)
  • Learning abstract data types.
  • Applying data structures in Python.

Why is C considered a foundational language?

<p>Many programming languages and interpreters are based on it. (C)</p> Signup and view all the answers

Which of the following is NOT a listed feature of the C programming language?

<p>Automatic garbage collection. (B)</p> Signup and view all the answers

Which of the following is not an application of the C language?

<p>Managing relational databases. (D)</p> Signup and view all the answers

What makes the Data Structures II course a required core course?

<p>It provides understanding of data structures at the memory and CPU level. (B)</p> Signup and view all the answers

What percentage is the final exam worth in the overall grade for CP264?

<p>45% (A)</p> Signup and view all the answers

Dennis Ritchie is credited with the creation of which programming language?

<p>C (B)</p> Signup and view all the answers

Which organization standardized the C programming language in 1989, resulting in what is known as 'ANSI C' or 'C89'?

<p>ANSI (American National Standards Institute) (C)</p> Signup and view all the answers

C is considered a procedural programming language. What does this imply about its structure?

<p>It uses program controls, blocks, and subroutines. (B)</p> Signup and view all the answers

Bjarne Stroustrup created which language as an extension of C?

<p>C++ (C)</p> Signup and view all the answers

What is the role of a compiler in the C programming environment?

<p>To convert source code into executable machine code. (B)</p> Signup and view all the answers

What is the first step in the C compiling process?

<p>Pre-processing (C)</p> Signup and view all the answers

What is the purpose of the linking step in C compilation?

<p>Combining object programs to create an executable file. (D)</p> Signup and view all the answers

Which command is used to compile a C program hello.c using the GCC compiler with the default C99 standard?

<p>gcc hello.c (D)</p> Signup and view all the answers

What does the command gcc -c hello.c do?

<p>Creates an object file named <code>hello.o</code>. (D)</p> Signup and view all the answers

What is the file extension for C language header files?

<p>.h (B)</p> Signup and view all the answers

During C program execution, where is the executable loaded?

<p>Main memory (D)</p> Signup and view all the answers

Flashcards

What are Data Structures?

Data structures define how data are represented, organized, stored, and operated in programs and computers.

Why are data structures essential?

Data structures are essential for data representations and operations. Critical for time and space efficiency of algorithms and programs.

What is CP264?

Going deep into data structure design, analysis and implementation at a low memory level, using the C programming language.

Fundamental Data Structures

Arrays, linked lists, queues, stacks, trees, hash tables, heaps, and graphs.

Signup and view all the flashcards

Why learn C?

C is a foundation of programming languages being over 50 years old. Many programming languages are based on it. Many interpreters are written in C.

Signup and view all the flashcards

Applications of C

C is used to write operating systems, high performance application programs, and programs for embedded systems.

Signup and view all the flashcards

Key features of C

C is a high level compiled program language. Capable of memory address and bit level operations. Small, extensible, stable, and portable.

Signup and view all the flashcards

Why use C in DS II?

To understand how data structures work in programs at the memory and CPU instruction level.

Signup and view all the flashcards

Why is DS II a core course?

DS II provides understanding of how data structures and programs work at a memory and CPU level. Provides foundational knowledge and skills for computer science and software engineering.

Signup and view all the flashcards

Who created UNIX and C?

Ken Thompson created the UNIX OS. Dennis Ritchie created C to export UNIX.

Signup and view all the flashcards

C Standardization

First C standard was the ANSI C or C89 approved in 1989. Revised C standard was C99 in 1999. Followed by C11, C17, and C23.

Signup and view all the flashcards

C as a compiled language

It writes source code in an understandable form, converted to machine code, then loaded to memory to run.

Signup and view all the flashcards

What is a Compiler?

Compiler converts source code to executable programs and are available for most computer platforms.

Signup and view all the flashcards

C's features: small, simple and powerful.

C has 32 keywords with a simple syntax and program structure. It Supports memory address operations and bitwise operations are processor instruction operations.

Signup and view all the flashcards

C's nature: stable, portable, extensible

C is stable due to its standardization, is portable, and is extensible because it allows adding libraries.

Signup and view all the flashcards

C as procedural language

A procedural language featuring program controls, blocks, and subroutines with functions (procedure, routine, or subroutine) calls.

Signup and view all the flashcards

Applications of C

C writes all OS kernels, device drivers, system programs, utility programs, compilers (like UNIX, Linux, Windows, Mac OS). It writes other programming language interpreters(Python, PHP, Java, JavaScript) and high-performance computing.

Signup and view all the flashcards

Pre-processing

Resolve lines with pre-processor directives (lines start with #).

Signup and view all the flashcards

Compilation

Covert the C program into assembly program.

Signup and view all the flashcards

Assembling

Convert the assembly to binary format, called object programs.

Signup and view all the flashcards

Study Notes

Data Structures

  • Data structures define how data is represented, organized, stored, and operated on.
  • They are essential for data representation and critical for time and space efficiency in programming.

CP164 vs CP264

  • CP164 covered basic data structure concepts, abstract data types (ADT), fundamental data structures, and application programming in Python.
  • CP264 delves deeper into data structure principles, focusing on design, analysis, and implementation in C at a low memory level.
  • CP264 covers arrays, linked lists, queues, stacks, trees, hash tables, heaps, and graphs.
  • CP264 involves the design, analysis, and implementation of high-performance, application-specific data structures in C.

Why C?

  • C is a foundational programming language that is over 50 years old and also the first standardized one.
  • Many languages and interpreters are based on C, including C++, Java, C#, Python, PHP, and JavaScript.
  • C is used in operating systems, high-performance applications, and embedded systems.
  • C has powerful features such as being a high-level compiled language, capable of memory address and bit level operations, and is small, extensible, stable, and portable.

Why C in Data Structures II?

  • Data structures are understood fundamentally in terms of memory and CPU instruction level.
  • It allows for design and implementation of data structures down to the memory level.
  • C enables the design and implementation of application-specific data structures for improved performance

Why Data Structures II?

  • Data Structures II provides an understanding of how data structures and programs function at memory and CPU levels.
  • It provides foundational knowledge for computer science and software engineering careers.
  • Data Structures II serves as a foundation for courses like Algorithm Design & Analysis I, System Programming, Operating Systems, and Computer Graphics.

Course Structure

  • The course includes 12 weekly lessons serving as a textbook with self-evaluated quizzes.
  • There are 34 lectures focused on core concepts, principles, and delivered with notes/slides, demonstrations, and Q&A.
  • It also includes 10 graded individual labs for data structure programming in C, submitted through MyLS.
  • There are 10 graded individual assignments for designing and implementing data structures in C, submitted via MyLS.
  • The course has midterm and final exams that test lectures, lessons, and assignments, and are in person and paper based.

Evaluation Breakdown

  • 10 labs are 10% of the grade
  • 10 assignments are 30% of the grade
  • The Midterm is 15% of the grade
  • The Final Exam is 45% of the grade
  • All tasks count with no dropping and weight transfer.
  • A minimum of 50% is required on the final exam and a 50% overall grade to pass.

Introduction to the C Language

  • C is a general-purpose language created by Dennis Ritchie at AT&T Bell Labs (1969-1973).
  • UNIX OS was created by Ken Thompson, and Dennis Ritchie invented C to export UNIX to different platforms.
  • ANSI approved the first C standard in 1989 (ANSI C or C89).
  • ISO approved a revised standard in 1999 (C99), followed by C11, C17, and C23.

C Features

  • C is a compiled programming language where source code is converted to machine code.
  • A compiler converts source code to executable programs.
  • C is small, simple, but powerful, with 32 keywords and supports memory address operations.
  • Bitwise operations are processor instruction operations.
  • C is stable and portable due to standardization, allowing compilation by cross-platform compilers.
  • Libraries can be added for extended functionalities, making C extensible.
  • C is the primary language for the procedural programming paradigm, featuring structured programs with program controls, blocks, and functions.

C Applications

  • C is used for writing OS kernels, device drivers, system and utility programs, such as Unix, Linux, Windows, and macOS.
  • C is used for interpreters of languages like Python, PHP, Java(JVM), and JavaScript.
  • C is used for high-performance computing, graphics programs, browsers, GUIs, and large-scale parallel programs.
  • C influenced C++ (Bjarne Stroustrup, 1979), an extension for OOP.
  • Java (James Gosling, 1984) is an OOP language that runs on JVM, like C++.

Compiling and Execution

  • A simple "hello world" program in the C language looks like:
#include <stdio.h>
void main() {
 printf("hello, world\n");
}

C Compilation Steps

  • Pre-processing resolves lines starting with "#", using pre-processor directives.
  • Compilation converts the C program into assembly code.
  • Assembling converts assembly code into binary object programs.
  • Linking combines object programs to create an executable (binary machine code program).

C Compilers

  • C Compilers are programs that compile C Code
  • MinGW (Minimalist GNU C Compiler for Windows) is one such compiler.
  • Mac OS includes Clang as a compiler.
  • Command-line compilation: gcc hello.c uses the default C99 standard.
  • This creates a.exe on Windows or a.out on Linux/Mac (executable program).
  • Execute programs via command line, i.e. a.exe on Windows or ./a.out on Linux/Mac

Compiler Options

  • -std=c99 is used to enforce the C99 standard.
  • The command for this would be gcc -std=c99 hello.c
  • -c suppresses linking during compilation and generates an object file.
    • For instance gcc -c hello.c will output hello.o
  • -g embeds diagnostic information into the object file.
    • For instance gcc -g hello.c will output a.exe
  • -o names the executable program from linking instead of a.out.
    • For instance gcc hello.c -o hello.exe, or gcc hello.c -o hello.
  • -S suppresses assembling and linking.
    • For instance gcc -S hello.c to generate the assembly filehello.s.
  • -On (optimize) is used to optimize, 0 is off, default is 1, 2,3,6 are higher optimization levels.
    • For instance gcc -O3 -o hello hello.c => hello.exe (executable, optimized with level 3)
  • -Wall command gives compiling warnings.
  • -Idirectory command gives the list of directories for include files.
  • -larg command searches /lib and /usr/lib for library libarg.lib.
  • -Ldirectory provides a list of directories for library specific files by -l.

File Extensions

  • .c is a C language source code file.
  • .h is a C language header file.
  • .exe is an executable file (or .out for Unix/Linux).
  • .o is an object file.
  • .s is an assembly language source file.
  • .lib is a static library of object modules (.a for Unix/Linux).
  • .dll is a dynamic library file (.so for Unix/Linux).

C Program Execution

  • The executable program, consisting of instructions, is loaded into the main memory.
  • Execution starts from the first instruction of the main function, one by one controlled by the program's flow control, stopping at the end.
  • When executing, an instruction is read from memory to the CPU register and then executed by the CPU.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

Use Quizgecko on...
Browser
Browser