Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C Programming #define? [duplicate]

Possible Duplicate:
Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc…)

#include<stdio.h>
#include<conio.h>

#define SQ(x) x*x

void main()
{
   int a1 , a2;
   int b1 , b2;

   a1 = 2;
   a2 = 2;

   b1 = 0;
   b2 = 0;

   b1 = SQ(a1++);
   b2 = SQ(++a2);

   printf("Frist = %d",b1);
   printf("Second = %d",b2);
}

I know what is the output of the code.

as #define work in other programe that way it is not working in above code Why.?

like image 540
Nirav Avatar asked Nov 02 '10 15:11

Nirav


People also ask

What is C used for in programming?

C is a programming language that is both versatile and popular, allowing it to be used in a vast array of applications and technologies. It can, for example, be used to write the code for operating systems, complex programs and applications, and everything in between.

What is C programming concept?

C is an imperative procedural language supporting structured programming, lexical variable scope, and recursion, with a static type system. It was designed to be compiled to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support.

Is C and C++ programming same?

Conclusion. In a nutshell, the main difference between C and C++ is that C is a procedural with no support for objects and classes, whereas C++ is a combination of procedural and object-oriented programming languages.

Is C better than Python?

Python vs C Summary In brief, C is an older, compiled, low level, procedural programming language. It has more control over itself and the computer, and it runs faster. Python, on the other hand, is an interpreted, high level, and object oriented programming language that's easier to learn.


1 Answers

The result of an expression with more than one ++ operator on the same variable is officially an undefined behavior in C.

like image 53
Seva Alekseyev Avatar answered Oct 02 '22 04:10

Seva Alekseyev