C Flashcards
(39 cards)
What is the main method in C?
-Starting point of your C application
-Returns an int
-If returned value is not provided, defaults to return 0
What is 0 indicate by convention?
Valid exit
What does a non-zero indicated by convention
Some kind of error to the calling program
What are C programs complied into?
Object code by a compiler
What does the pre-processor cpp do ?
It examines the source code before the compiler:
-it identifies any special cpp directives
-it re-writes source code into an intermediate source file
-it passes the new source file to the compiler
What are the 3 forms of cpp directives?
1.File inclusion:
-#include <file>: paste a file directly into your source code
2.Macros:
-#define <content>: these are pure textual substitutions
3.Conditional inclusions:
-#ifndel <label></label></content></file>
What is important to remember about cpp directives?
They are not part of the C language. Gcc never knows anything about them, because it only sees the extended output created by cpp.
What is an example of a standard header file ?
stdio.h
Why is it important to have header files?
They contain declarations for various functions–> declarations provide basic type information for the compiler.
Since the compiler compiles each source file independently, it does not know that this function is properly defined in another source file.
What does #include <stdio.h> do?</stdio.h>
It includes a declaration for the printf() function
What is the error “Symbol could not be resolved” mean?
You have probably forgotten the associated header file.
What is the basic form use of printf()?
printf(formatting string, variable list);
What are the 5 main C data types?
d :decimal integer
f :floating point value
s :character string
c :individual character
p :pointer address value
C is a … language?
An imperative, procedural language
What are imperative languages?
They use a series of statements, each of which can modify the state of the program.
What is the difference between imperative and declarative languages?
Imperative –> HOW to produce its output
Declarative(SQL)–> WHAT output you would like to see
What is a procedural language?
It indicates that programming logic can be encoded as procedures or sub-routines that can be called from other locations in the code.
MOST BASIC FORM OF STRUCTURED PROGRAMMING
What do OO languages do that imperative procedural languages don’t?
OO languages –>use methods to provide sub-routines + couple data with the methods that operate on them.
C IS NOT OBJECT ORIENTED LANGUAGE
What is the gcc invocation used for?
To compile several source files into a single executable
What is a header guard?
They ensure that only one copy of this header file gets included in your source file.
What is the -Wall flag used for?
It prints all warnings
What is different about C methods from Java methods?
There are no public/private methods. –> all functions are externally visible
We can use static to tell the compiler that this function can only be referenced/invoked from the source file in which it is written.
What is the main difference between C and Java(architecture)?
Java is standardized across all CPU architectures i.e int is always 4 bytes
C isn’t i.e int may be 2,4 or 8 bytes
How do we determine the byte count of a given primitive type?
Using sizeof()