How to use pre and post increment and decrement operators with functions in C

4 Answers

0 votes
#include <stdio.h>
 
int function(int x)
{
    return x;
}

int main(void)
{
    int x = 13;
        
    int y = function(x++);  
    
    printf("y = %d x = %d\n", y, x);
        
    return 0;
}

   
/*
run:
 
y = 13 x = 14

*/

 



answered Sep 2, 2017 by avibootz
0 votes
#include <stdio.h>
 
int function(int x)
{
    return x;
}

int main(void)
{
    int x = 21;
        
    int y = function(x--);  
    
    printf("y = %d x = %d\n", y, x);
        
    return 0;
}

   
/*
run:
 
y = 21 x = 20

*/

 



answered Sep 2, 2017 by avibootz
0 votes
#include <stdio.h>
 
int function(int x)
{
    return x;
}

int main(void)
{
    int x = 38;
        
    int y = function(++x);  
    
    printf("y = %d x = %d\n", y, x);
        
    return 0;
}

   
/*
run:
 
y = 39 x = 39

*/

 



answered Sep 2, 2017 by avibootz
0 votes
#include <stdio.h>
 
int function(int x)
{
    return x;
}

int main(void)
{
    int x = 45;
        
    int y = function(--x); 
    
    printf("y = %d x = %d\n", y, x);
        
    return 0;
}

   
/*
run:
 
y = 44 x = 44

*/

 



answered Sep 2, 2017 by avibootz

Related questions

1 answer 256 views
1 answer 177 views
1 answer 175 views
3 answers 328 views
3 answers 229 views
...