Tricks and common doubts in C and C++


1.How to change font style and font size in c program?
Answer:  To turn bold on and off you need to call the library term.h if you are on linux and then implement this function :
printf("Normal text\n");
system("setterm -bold on");
printf("Bold text\n");
system("setterm -bold off");

2.


3. If I use getch();
then is it necessary to use #include < conio.h > ?
Answer: YES.

4. What is Stack ?
Answer: Stack is collection of books ( elements ) where you can keep book on top that is push and you can remove book from top only this is pop . Removing book from between and down can fall the upper book.
Last in first out. ( means only on top insertion and deletion can happen ).

5. How many dimensions can an array have?
Answer: Nth dimensions (Multidimensions).

6. What is inheritance?
Answer: Simple when one class inherit some properties of preceding class it's called inheritance let take a example when child have some properties of their parents.
i.e. Inheritance is a process of creating new classes from existing classes where the new classes inherits some of the properties of its parent class.

7. How can I print the memory size and memory address of a variable?
Example: int a[10]={10,20,30,40,50,60,70,80,90,100};
Answer: For memory size - sizeof operator ex: sizeof(a),
For address of a variable- &x(x is here the variable)
If you want to have the adress of ith element of an array - (a+i)
If you want value of i th element - *(a+i)

8. What it does mean (invalid preprocessing directive #include) in c programming?
Answer: The #include at the top of your program is a preprocessor directive; you are using an invalid include, or your syntax is wrong.

9. What is the use of "for loop" in cpp?
Answer:  To repeat something a certain number of times, or until criterion is met. i.e. to avoid the redundancy of the same set of codes.

10. What is a recursive function?
Answer: when a function call itself repeatedly then this is known as recursive function.and yes main function can also be recursive.  Just remember that a recursive function must also have an update and an exit condition to pop the stack and return.

11. How can I change text colour in c?
Answer:  You can say: printf("%sblue\n",s); to print the string in the color blue. I may be wrong though. I don't have a terminal handy right now.

12. How we can print %d as an output? the output we get should be %d.
Answer: You need to tell C compiler to treat % as a normal character, rather than assuming it as a beginning of format specifier. Do it this way. printf("%%d");

No comments