lOMoARcPSD|34978648
FAQs CS201 - Introduction to Programming
Introduction to programming /c++ (Virtual University of Pakistan)
Scan to open on Studocu
Studocu is not sponsored or endorsed by any college or university
Downloaded by Razia Mehboob (
[email protected])
lOMoARcPSD|34978648
FAQs
Question: What are pointers?
Answer: A pointer is a variable that represents/stores location of a data item, such as a variable
or array element
Question: What’s the difference between void main and int main?
m
Answer: Void main (): You can't return a value from void main. i.e., you can't return 0; at the
end of main (). You can use "return;" but no value is passed back to any program that
co
called it. This may not seem like much of a problem to you at this point; but it *will*
become important as you create more complex programs.
int main (): Returns a integer value at the end of execution. The value returned can be
y.
a standard 0 or any other int to represent and number of errors/choices/results/etc... int
main () is a standard.
Go for int main (), if for no other reason than that it’s a good coding habit. It’s no
ud
harder to type "return 0;" than "return;", and it will save you time in the future.
Question: What is #include? st
Answer: #include is pre-processor macro. Preprocessor includes the whole file you specify
with it so basically it's same as you would write the whole header file in your
ne
program. However program's size doesn't increase by including files. It's linker's duty
to link only symbols that are needed and leave others behind. The program file will
start with #include statements that tell the compiler to read the "headers" describing
bi
the libraries that the program uses.
m
Question: What does main( ) do?
Answer: Main ( ) provides the entry point into the program. Compilers only recognize
co
statements that are with in the braces of main ( ), all other functions are called from
main ( ). For more help visit http://www.cs.uow.edu.au/people/nabg/ABC/C6.pdf
w.
Question: What do compound statements mean?
Answer: Grouping of statements is called "compound statements". C and C++ use
ww
{ ("begin bracket")
and }
("end bracket")
to group the set of statements that form the body of a loop.
while ( Expression ) {
statement-1;
statement-2;
...
statement-n;
lOMoARcPSD|34978648
Question: Why we use function prototypes?
Answer: A function prototype is a declaration that defines both: The arguments passed to the
function and the type of the value returned by the function.
The c++ compiler uses this prototype to ensure that the types of the arguments you
pass in a function call are same as those mentioned in the prototype. If there is a
mismatch the compiler points it out immediately.
m
This is known as strong type checking, something which C lacks.
co
Question: What is an Array?
Answer: An array is a data structure that allows storage of a sequence of values. The values are
y.
stored in a contiguous block of memory. Arrays allow fast random access to particular
elements. If the number of elements is indefinite or if insertions are required then we
can’t use an array. Example:
ud
int idnumbers[100];
This declares an array of 100 integers named idnumbers.
Question:
st
What is the relation between pointers and Arrays?
Answer: There is an important relation between pointers and arrays. By defining: int a[10]; “a”
ne
by itself is of type (int *) - a pointer to int, and has the value &a[0] (the address of
a[0]). So we can do the following: int *pa = a; since pointers are just numbers (i.e.
numeric memory addresses) we can do arithmetic operation on them:
bi
int *pb = pa+1; /* now pb points to a[1] */
m
*pb = 1; /* now a[1] = 1 */
*(pb + 2) = 3; /* now a[3] = 3 */
co
Question: When I compile a file in Dev-C++, I get a message saying "could not find file name“
Answer: Check in Compiler options if the directories settings are correct. With a default setup,
w.
you should have :
C:\DEV-C++\Bin
c:\DEV-C++\Include
ww
c:\DEV-C++\Include
c:\DEV-C++\Lib
For further help in Dev C++, you must consult Help on Dev C++, given in the help
menu
Question: I am having problems using Borland specific functions such as clrscr()
Answer: If you are using Dev-C++ 4 then include conio.c else include conio.h in your program
file. For further help in Dev C++, you must consult Help on Dev C++, given in the
lOMoARcPSD|34978648
help menu.
Question: Are there any other books for reference than C++ how to program?
Answer: Yes there are many some of them are listed below:
· Sams Teach Yourself C++ in 21 Days by Jesse Liberty
· C++ Primer by Lippman and Lajoie
m
· Essential C++ by Stanley Lippman
co
· The C++ Programming Language by Bjarne Stroustrup
y.
· The C Programming Language by Brian Kernighan and Dennis Ritchie
· The C Answer Book by Gimpel and Tondo
ud
Question: What is Dev-C++? st
Answer: Dev-C++ is a C++ IDE in which we can write C++ code, compile and run it. It has
both Compiler and Editor in it.
ne
Question: Why are we using Dev-C++?
Answer: We are using Dev-C++ because it is a Freeware. Freeware is such a software which is
bi
available for free and anyone can use it and take the benefit of it.
m
Question: Difference between getch( ) getche( ) and getchar( ) functions.
co
Answer: getch ( ) is used when you want to get a character from the user via keyboard. getch (
) does not display the character pressed by the user from the keyboard. It returns
ASCII Code of the character pressed by the user.
w.
getche ( ) works same like getch ( ) except it displays the character pressed by the
user. It returns ASCII Code of the character pressed by the user.
getchar ( ) works like getch ( ) and getche ( ) except it will continue inputting the
character until Enter is pressed. It returns the ASCII Code of first character entered by
ww
the user
Question: What is a rand () function?
Answer: rand ( ) is a random number generator function. The function rand ( ) returns a value
between 0 and 32767
Question: What is the difference between exit ( ) and exit (1)
lOMoARcPSD|34978648
Answer: exit ( ) terminates the calling process. if 0 is passed to the exit (0) its a Normal
termination and if 1 is passed ,exit (1) , then its an Abnormal termination. Error in
process
m
co
y.
ud
st
ne
bi
m
co
w.
ww