Ad
Thursday, February 16, 2023
Advanced C Programming Questions and Answers
Q. What is pointer?
syntax: int *ptr
Q. Concept of pointer to pointer with example.
Answer: A pointer is used to store the address of a variable in C. However, In C, we can also define a pointer to store the address of another pointer. Such pointer is known as a double pointer (pointer to pointer). The first pointer is used to store the address of a variable whereas the second pointer is used to store the address of the first pointer.
Q. What is formal parameter and actual parameter.
Answer:
Formal Parameter: The Formal Parameters are the variables defined by the function that receives values when the function is called. The data types of the receiving values should be included.
Actual Parameter: The Actual parameters are the values that are passed to the function when it is invoked. Only the value is mentioned.
Q. What is dynamic memory allocation?
Answer: Dynamic memory allocation allows a program to obtain more memory space, while running or to release space when no space is required.
Functions of Dynamic memory allocation:
- malloc () : It allocates requested size of bytes and returns a pointer first byte of allocated space.
- calloc(): It allocates space for an array element initialized to zero and then returns a pointer to memory.
- free(): It deallocates previously allocated memory. It releases space explicitely.
- realloc(): It re-allocates memory, i.e. changes the size of previously allocated memory.
Q. What is meaning of & and * operator in pointer?
* is a unary operator that returns the value of the variable at the address specified by its operand.
Q. Give Syntax and use of following functions/ list of functions in strings.
- strlen
- strcat
Answer: The strlen() function calculates the length of a given string.
- strcmp
Answer: The strcmp() compares two strings character by character. If the strings are equal, the function returns 0.
- strcpy
Answer: The strcpy() function copies the string pointed by source (including null character) to the destination.
- strrev
Answer: The strrev() function is used to reverse the given string.
Q. Give the difference between structure and union.
Answer:
Sr. No. | Factors | Structure | Union |
1 | Definition | It is a collection of logically related elements of similar or different types. | It is a collection of logically related elements of similar or different types with single memory location. |
2 | Accessing members | All members can be accessed at any time. | Only one member can be accessed at any time. |
3 | Memory allocation | Memory allocated to all members. | Memory allocated for member with largest size. |
4 | Initialization | All members can be initialized. | Only the first member can be initiallized. |
5 | Size | Equal to or greater than size of it’s members. | Equal to size of largest member. |
6 | Keyword | ‘struct’ | ‘union’ |
Q. Define file. Explain any four file functions.
Answer: A collection of data which is stored on a secondary device like a hard disk is known as a file.
File functions:
fopen() : Opens new or existing file.
fprintf() : Write data into file.
fscanf() : Reads data from the file.
fclose() : Close the file.
Q. Define Macro.
Answer: Macro is an abbrevation for sequence of instructions. When it is used in the program, then defined sequence of instructions are submitted over there.
Q. What are command line arguments ? How are they declared ?
Answer: Command line arguments are nothing but simply arguments that are specified after the name of program in the system's command line, and these argument values are passed on to your program during your program execution.
Declaration:
int main(int argc, char *argv[]) { /* ... */ }
Q. Explain nesting of macros.
Answer: A macro name within another macro is called nesting of macro. The called macro is "inner macro" and calling macro is "outer macro".
Syntax:
#define identifier1(f1,f2,...,fn)string1
#define identifier2(identifier(f1,f2,....,fn)*(e1,e2,e3.....,en))string2
About Abhishek Dhamdhere
Qna Library Is a Free Online Library of questions and answers where we want to provide all the solutions to problems that students are facing in their studies. Right now we are serving students from maharashtra state board by providing notes or exercise solutions for various academic subjects
No comments:
Post a Comment