C Flashcards

1
Q

History of c

A

-Ritchie and Thompson 1973
Rewrite UNIX kernel with C
-Richie and Kernaghan
Created the “C programming language”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

C

A
  • general purpose language
  • equally usable for applications programming and systems programming (network protocol, database management system, write a compiler)
  • ubiquitous (where find C you find UNIX)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Features of C

A

-most toolchains have relatively small footprint
Popular choice for developing embedded systems
Operating systems research and development
Good choice for systems programs that one expects to port

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Compile time features

A
  • ANSI-compliant compilers provide extensive compile-time diagnostics
  • also provide a continuum of optimizations
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Run time features

A

-easy to adapt a C compilers output to the execution environment on a platform

Missing features

  • no native array bounds checking
  • no null pointer checkers
  • no uninitialized vars check
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Aggregate data types

A
  • struct: one mechanism to declare user-defined types
  • arrays: can be set scaler or aggregate
  • union: similar to structs, but members are overlaid
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Static and extern

A
  • internal linkage

- external linkage

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Addresses and pointers

A
  1. All bars refer to data
  2. All data resides in memory
  3. Every memory location has an address
  4. C exposes these details for us to use
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Program scope

A

Var exists for programs lifetime and can be accessed from other files (extern)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

File scope

A

Visible from its declaration to end of source file

Static

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Function scope

A

Visible from begging to end of function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Block scope

A
  • visible from form declaration to end of the block

- block is curly brackets

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

C preprocessor

A
  • separate program that runs before the compiler

- allows macro processing, inclusion of additional C source files, conditional compilation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Macro processing

A
  • a name that has an associated text string

- macros introduced from #define

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Standard headers

A
Stdio.h : standard I/O library funcs 
Math.h : math funcs
Stdlib.h : memory allocation funcs and general utility funcs
string.h : string funcs
ctype.h : char testing and mapping funcs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Abstract data type

A

-an abstract data type is a set of operations which access a collection of stored data

17
Q

FILE *fopen(char *filename, char *mode)

A
  • open file corresponding to filename
  • can be r rw or rw+
  • if errors occur returns null
18
Q

char *fgets(char *buf, int n, FILE *stream)

A
  • read at most n-1 chars from stream and copy to location buf. Terminates when newline or n-1 chars
  • returns null if EOF or error
  • set stream to stdin to accept input from standard input
19
Q

int scanf(char *format, […])

A
  • read formatted data from standard input
  • returns EOF Shen encountered else returns number of fields successfully converted
  • format specifiers encoded in format
20
Q

printf(char *format, […])

A
  • print formatted output to standard output
  • returns the number of chars printed
  • the format specifiers are encoded in the string format
  • takes a variable # of arguments
21
Q

int fprintf(FILE *stream, char *format, […])

A

-like printf but output goes to already opened stream

22
Q

int fputc(int c, FILE *stream)

A
  • outputs a single char to already opened stream
  • character is stored in an int
  • num from 0 to 255
  • can also pass a char as the first parameter
23
Q

int fclose(FILE *stream)

A
  • closes the stream (flushes all OS buffers such that output file is completed)
  • dissociates the actual file from the stream variable
  • returns 0 if file closed properly