{"id":3294,"date":"2024-03-05T12:49:07","date_gmt":"2024-03-05T12:49:07","guid":{"rendered":"https:\/\/www.skillvertex.com\/blog\/?p=3294"},"modified":"2024-03-05T12:49:07","modified_gmt":"2024-03-05T12:49:07","slug":"and-operators-in-c","status":"publish","type":"post","link":"https:\/\/www.skillvertex.com\/blog\/and-operators-in-c\/","title":{"rendered":"# And ## Operators In C"},"content":{"rendered":"\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\" id=\"rank-math-toc\"><p>Table of Contents<\/p><nav><ul><li ><a href=\"#and-operators-in-c\"># And ## Operators In C<\/a><\/li><li ><a href=\"#example-to-show-the-usage-of-the-stringizing-operator\">Example- to show the usage of the stringizing operator(#).<\/a><\/li><li ><a href=\"#token-pasting-operator\">Token-pasting operator (##)<\/a><\/li><li ><a href=\"#example-to-show-the-usage-of-token-pasting-operator\">Example- to show the usage of  Token-pasting operator (##)<\/a><\/li><li ><a href=\"#application-of-token-pasting-operator\">Application of Token-pasting operator (##)<\/a><\/li><li ><a href=\"#faq-and-operators-in-c\">FAQ-  # and ## Operators in C<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"and-operators-in-c\"># And ## Operators In C<\/h2>\n\n\n\n<p><strong>Stringizing operator (#)<\/strong><\/p>\n\n\n\n<p>This stringizing operator is a preprocessor operator which will cause a corresponding actual argument and will be enclosed in double quotation marks. This # operator is known as the stringize operator. This operator will change the argument that will precede into a quoted string.  This is known as the stringification operator. This is mostly used with macros in C.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"example-to-show-the-usage-of-the-stringizing-operator\"><strong>Example<\/strong>&#8211; to show the usage of the stringizing operator(#).<\/h2>\n\n\n\n<p>The C code provided below will show the usage of the stringizing operator(#).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ C program to illustrate (#) operator \n#include &lt;stdio.h&gt; \n  \n\/\/ Macro definition using the stringizing operator \n#define mkstr(s) #s \nint main(void) \n{ \n    \/\/ Printing the stringized value of \"Skillvertex\" \n    printf(mkstr(Skillvertex)); \n    return 0; \n}<\/code><\/pre>\n\n\n\n<p>Output <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Skillvertex<\/code><\/pre>\n\n\n\n<p>Explanation<\/p>\n\n\n\n<p>The preprocessor will change the line printf (mkstr(Skillvertex)); into printf(\u201cSkillvertex\u201d);<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"token-pasting-operator\">Token-pasting operator (##)<\/h2>\n\n\n\n<p>The <strong>Token-pasting operator <\/strong>will enable tokens which will be used as actual arguments and further, it will be linked to form other tokens. Therefore, it can merge two tokens into one during the expansion of macros. This process is known as token pasting or token concatenation. <\/p>\n\n\n\n<p>The &#8216;##&#8217; pre-processing operator in C\/C++ is used for something called &#8220;token pasting.&#8221; When you expand a macro, this operator combines the two tokens on either side of &#8216;##&#8217; into a single token. This combined token replaces the &#8216;##&#8217; and the original two tokens in the macro expansion. This can be useful for creating new tokens or identifiers during the preprocessing stage.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"example-to-show-the-usage-of-token-pasting-operator\">Example- to show the usage of  Token-pasting operator (##)<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ C program to illustrate (##) operator \n#include &lt;stdio.h&gt; \n  \n\/\/ Macro definition using the Token-pasting operator \n#define concat(a, b) a##b \nint main(void) \n{ \n    int xy = 30; \n  \n    \/\/ Printing the concatenated value of x and y \n    printf(\"%d\", concat(x, y)); \n    return 0; \n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>30<\/code><\/pre>\n\n\n\n<p>Explanation:<\/p>\n\n\n\n<p>The preprocessor will change &nbsp;printf(\u201c%d\u201d, concat(x, y)); into printf(\u201c%d\u201d, xy);<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"application-of-token-pasting-operator\">Application of Token-pasting operator (##)<\/h2>\n\n\n\n<p>The &#8216;##&#8217; operator in C\/C++ macros is used to concatenate or join actual arguments during macro expansion. If a parameter in the replacement text is next to a &#8216;##&#8217;, the parameter is replaced by the actual argument. The &#8216;##&#8217; and any surrounding white space are removed, and the combined result is then re-scanned by the preprocessor. This can be helpful for generating new tokens or combining values in a flexible way during preprocessing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"faq-and-operators-in-c\">FAQ-  # and ## Operators in C<\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1699352885837\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q1. What is the ## operator in C?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. In the C language, the &#8216;##&#8217; operator serves as a token-pasting operator in the preprocessor. It is employed to combine two tokens during the preprocessing stage of compilation. So, essentially, the &#8216;##&#8217; operator concatenates the string &#8220;foo_&#8221; with the token &#8220;a&#8221; to create the string &#8220;foo_a,&#8221; and similarly, it combines &#8220;bar_b&#8221; by joining &#8220;bar_&#8221; and &#8220;b&#8221; together.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1699352896465\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q2. What does &amp; and * mean in C?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans.In C and C++, when you see the symbol &#8220;&amp;,&#8221; it means &#8220;get the memory address of.&#8221; This is often used in function parameters to allow functions to change the original variable. By default, C and C++ pass copies of variables to functions, but using the &#8220;&amp;&#8221; lets you pass the original variable&#8217;s address instead, so changes made in the function affect the original.<br \/>On the other hand, when you see the &#8220;&#8221; symbol with a pointer, it means &#8220;get the value stored at that memory address.&#8221; So, if you have a pointer named <code>ptr<\/code>, &#8220;ptr&#8221; gets the value located at the memory address pointed to by `ptr.&#8221;<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1699352907398\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q3. What is the logical &amp;&amp; operator in C?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. The logical AND operator (&amp;&amp;) in programming is a binary operator that works with two values and produces a result. It returns true or 1 only if both of its operands are true. If either one is false, it returns false or 0. In simpler terms, both conditions must be true for the AND operator to yield a true result; otherwise, it gives a false result.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p># And ## Operators In C Stringizing operator (#) This stringizing operator is a preprocessor operator which will cause a corresponding actual argument and will be enclosed in double quotation marks. This # operator is known as the stringize operator. This operator will change the argument that will precede into a quoted string. This is &#8230; <a title=\"# And ## Operators In C\" class=\"read-more\" href=\"https:\/\/www.skillvertex.com\/blog\/and-operators-in-c\/\" aria-label=\"More on # And ## Operators In C\">Read more<\/a><\/p>\n","protected":false},"author":4,"featured_media":5410,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[550],"class_list":["post-3294","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-programming","tag-and-operators-in-c","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"_links":{"self":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/3294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/comments?post=3294"}],"version-history":[{"count":7,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/3294\/revisions"}],"predecessor-version":[{"id":7919,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/3294\/revisions\/7919"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media\/5410"}],"wp:attachment":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media?parent=3294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/categories?post=3294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/tags?post=3294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}