A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Stringizing Operator in C | How to print a variable name in C?
Q:

Stringizing Operator in C | How to print a variable name in C?

0

Stringizing Operator in C | How to print a variable name in C?

Stringizing Operator'#' in preprocessor directive is known as Stringizing Operator it is used to convert an argument into string format.

Print variable name using C program

Defining Macro:

#define macro_function(argument)    #argument

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the example

/*
C program to demonstrate example of
Stringizing Operator
*/

#include <stdio.h>

#define getVariableName(x) #x

int main()
{
    int student_age = 21;

    printf("value of %s is = %d\n", getVariableName(student_age), student_age);

    return 0;
}

Output:

value of student_age is = 21

Write a code for Debugging – print variable name with their values

#include <stdio.h>

#define printDebug(x) printf("\nvalue of "%s" is: %d\n", #x, x);

int main()
{
    int value1;
    int value2;

    value1 = 10;
    value2 = 20;

    printDebug(value1);
    printDebug(value2);

    return 0;
}

Output:

value of "value1" is: 10

value of "value2" is: 20

printDebug

In this macro variable is passing in x, The statement printf("\nvalue of "%s" is: %d\n",#x,x); #x will convert the given argument in string and x will return the value.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now