16. What is a program flowchart and how does it help in writing a program?
Ans:
A flowchart provides a visual
representation of the step by step procedure towards solving a given problem.
Flowcharts are made of symbols, with each symbol in the form of different
shapes. Each shape may represent a particular entity within the entire program
structure, such as a process, a condition, or even an input/output phase.
17. What are global variables and how do you declare them?
Ans:
Global variables are variables
that can be accessed and manipulated anywhere in the program. To make a
variable global, place the variable declaration on the upper portion of the
program, just after the preprocessor directives section.
18. In a switch statement, what will happen if a break statement is omitted?
Ans:
If a break statement was not
placed at the end of a particular case portion? It will move on to the next
case portion, possibly causing incorrect output.
19. What are pointers?
Ans:
Pointers point to specific areas
in the memory. Pointers contain the address of a variable, which in turn may
contain a value or even an address to another memory.
20. What is the use of a semicolon (;) at the end of every program statement?
Ans:
It has to do with the parsing
process and compilation of the code. A semicolon acts as a delimiter, so that
the compiler knows where each statement ends, and can proceed to divide the
statement into smaller elements for syntax checking.
21. What is static memory allocation and dynamic memory allocation?
Ans:
Static memory allocation: The
compiler allocates the required memory space for a declared variable. By using
the address of operator, the reserved address is obtained and this address may
be assigned to a pointer variable. Since most of the declared variable have
static memory, this way of assigning pointer value to a pointer variable is known
as static memory allocation. memory is assigned during compilation time.
Dynamic memory allocation: It
uses functions such as malloc( ) or calloc( ) to get memory dynamically. If
these functions are used to get memory dynamically and the values returned by
these functions are assigned to pointer variables, such assignments are known
as dynamic memory allocation. memory is assigned during run time.
22. Difference between arrays and pointers?
Ans:
Pointers are used to manipulate
data using the address. Pointers use operator to access the data pointed to by
them
Arrays use subscripted variables
to access and manipulate data. Array variables can be equivalently written
using pointer expression.
23. What is a method?
Ans:
Method is a way of doing
something, especially a systematic way; implies an orderly logical arrangement
(usually in steps).
24. What are the differences between malloc() and calloc()?
Ans:
There are 2 differences.
First, is in the number of
arguments. malloc() takes a single argument(memory required in bytes), while
calloc() needs 2 arguments(number of variables to allocate memory, size in
bytes of a single variable).
Secondly, malloc() does not
initialize the memory allocated, while calloc() initializes the allocated
memory to ZERO.
25. What is scope of a variable? How are variables scoped in C?
Ans:
Scope of a variable is the part of the program where the variable may
directly be accessible. In C, all identifiers are lexically (or statically)
scoped. See this for more details.
EmoticonEmoticon