Posts

Showing posts from September 5, 2020

What is a macro ? Explain how a macro is defined in C. Also explain major differences between a macro and a function. Explain a situation when macro should be prefered over function with an example.

 What is a macro? Explain how a macro is defined in C. Also explain major differences between a macro and a function. Explain a situation when macro should be preferred over function with an example? IN C language , A  macro  is a fragment of code that has been given a name. Whenever the name is used, it is replaced by the contents of the  macro . There are two kinds of  macros . You may define any valid identifier as a  macro , even if it is a  C  keyword. The preprocessor does not know anything about keywords.  macro  is preprocessed. When you use a  MACRO , the C preprocessor will translate all strings using  macro  and then compile. See the following example of Macro: #include<stdio.h> #define NUMBER 10 int main() {       printf ( "%d" , NUMBER);       return 0; Output: 10 Difference between macro and functions  MACRO FUNCTION Macro is Preprocessed Function...

What is a string ? Write a function in C for string concatenation. Without the use of inbuilt string function?

Image
 What is a String? Write a function in C for string concatenation. Without the use of an inbuilt string function. String A string is a data type used in programmings, such as an integer and floating-point unit, but is used to represent text rather than numbers. It is comprised of a set of characters  that can also contain spaces and numbers. For example, the word "hamburger" and the phrase "I ate 3 hamburgers" are both strings. Even "12345" could be considered a string, if specified correctly. Typically, programmers must enclose strings in quotation marks for the data to recognized as a string and not a number or variable name . String concatenation in C C program to concatenate two strings, for example, if the two input strings are "C programming," and " language" (note the space  before language), then the output will be "C programming language." To concatenate the strings, we use strcat function of string.h, to concatenate ...