C programming 1 Flashcards
this takes material from "C programming a modern approach" book , and sololearn app
which system is C language a product of?
UNIX operating system
what was UNIX programmed in originally? explain the history behind the changes
it was originally programmed in Assembly like the other operating systems of that time.
then thompson decided that a higher level language is required for further development of UNIX so he designed a small language named B which was based on BCPL.
after Ritchie joined the UNIX project he started working on an extended version of B and named it “NB” or new B , later as the language diverged more from B he changed the name to “C” , they rewrote the UNIX in C .
what language was B based on ?
it was based on BCPL
what was the old name for C language?
it was “NB” or New B ,at first
who made the C language?
Dennis Ritchie
where was UNIX made and by whom ?
at Bell Laboratories by Ken Thompson , Dennis Ritchie and others.
name some 4 C based programming languages and how they relate to C.
C++ : includes all C features of C but adds others like classes and more features to support OOP .
Java : is based on C++ and therefore inherits many of C features.
C# :is a more recent language, derived from C++ and Java .
Perl : was a fairly simple language but as it has grown it adopted many features from C language.
name 3 philosophies of the C language design.
1: it is a low level language.
2: it is a small language.
3: it is a permissive language.
what is meant that C language is low level? how is that important for systems programming?
it provides access to low level concepts like addresses and bytes which other languages try to hide.
it also provides operations that correspond closely to machines built-in instructions. so it can be fast as systems cannot afford to be slow.
how was C languages features kept small?
it was kept small by relying on a library of standard functions.
name 6 strengths of C language.
1: its efficient , regarding speed and running with limited memory.
2: its portable .
3: its powerful , it has a large collections of datatypes and operators which gives it power and it can do more with fewer lines.
4: its flexible , as it imposes few restrictions on the use of its features.
5 :has a standard library which has many useful functions.
6: integrated with UNIX and UNIX-like operating systems.
how did C become portable?
1 - it was associated with UNIX and ISO/ANSI early which prevented it from splintering into numerous dialects.
2 - its compliers are small and easily written which makes them widely available.
3- has many features that support portability.
name 3 weaknesses for C langauge
1 : its programs can be error prone.
2 : its programs can be hard to understand.
3 : its programs can be hard to modify.
name one reason C programs can be error prone.
its flexibility can make it error prone
name 6 ways you can ensure more effective use of C language .
1 : learn its pitfalls and avoid them.
2 : use software tools that make programs more reliable , like Lint for error analysis.
3 : take advantage of existing code libraries.
4 : adopt a sensible set of code conventions.
5 : avoid tricks and overly complex code.
6 : stick to standard.
what does Lint do?
Lint is a tool to check for potential errors .
how to get “Lint” tool ?
it is included as Splint in many linux distributions “secure programming lint” , and it can be download from splint.org for free.
what steps the C program takes to become executable ?
preprocessing : the program is given first to the preprocessor which obeys commands preceded by “#” which are known as directives , and makes modifications.
compiling ; the compiler translates to the machine instructions making “object code” .
linking : .the linker includes additional code to make the program executable .
in gnu/linux how to make the executable version of the file “pun.c” get named “pun” ?
we enter the following command in the command line while in the same directory as the file:
gcc -o pun pun.c
what is an IDE and what can it do?
IDE = integrated development environment.
it can edit , compile , link ,execute and debug a program without leaving the environment .
what are functions in C language , generally?
they are like building blocks of programs , known in other languages as subroutines and procedures .
what are the two types of functions in C based on their source?
there are two :
those written by the programmer
and
those provided as a part of C implementation which are known as library functions.
what is a statement in C ?
its a command to be run when the program is run .
what are storage locations called in C ?
Variables
what is the difference between different variable types in general ?
they are stored differently.
they have different operations that can be done on them depending on the type.
they can store different sizes or lengths depending on the variable type .
they can be slower or faster to work with , and appropriate or not .
where to put declarations and statements in main function in different C versions?
declarations should come first before statements inside main function.
but in C99 its allowed to not declare until before its needed , just like in C++ and Java .
what is it called when a variable is given a value?
assignment .
what happens when you divide two integers in C if the result has a number after the decimal point ?
the result / output gets truncated or “ rounded down” , it means any numbers after decimal point is lost.
what is an uninitialized variable in C and what happens if you try to access it ?
an uninitialized variable is a one that is not given an initial value yet
if you try accessing it you may get a random meaningless number or a program crash.
how to give a constant a name before main function?
by using macro definition through the directive “#define” .
what conventions are there for macro definitions in C?
it must be all in CAPS , and should be inside parentheses if it contains an operator in its value.
just for conventional purposes .
what is meant by identifiers in C ?
they are names given to Variables , Functions , Macros and other entities.
what are the rules for identifiers names in C ?
they can only contain letters ,numbers and underscores , and should start with a letter or an underscore but not a number.
they are case sensitive.
in C99 they can contain certain “universal characters names” as well .
what are some conventions for identifiers in C language ?
even if C language is case sensitive , variables should be different unless related.
one should either use all small letters and separate words with underscores , or use no underscores and capitalize words after the first word in .
unless they are macros then use all in Caps.
can keywords be used as identifiers ?
no , they are reserved .
what is meant by tokens in C , and what are some of them ?
they are basic units that cant be split inside them (using spaces or whitespace characters like tabs and newlines ) without changing their meanings , but you can usually insert whitespace characters between them safely and without limits.
some of them are :
keywords , identifiers , punctuation marks , string literals .
is splitting a string into lines without tricks legal in C ?
no , its illegal .
what does GCC stand for ?
it used to stand for GNU C compiler . but it was extended to include many other languages and now means : (GNU compilers collection )
what does GNU stand for ?
it stands for “GNU is Not UNIX” .
are : “exit (0) ;” and ‘return 0 ;” equivalents when they are inside main ?
yes