Tuesday, December 5, 2017

Difference Between i++ and ++i and their performance issue

Hello Listeners, today I'll show you the difference between i++ and ++i and their performance issue, cause many of my juniors have asked me to clarify between i++ and ++i. 


Difference Between i++ and ++i and their performance issue

Difference between i++ and ++i

Their is a difference between i++ and ++i . 

++i
++i will increment the value of i variable then returns the incremented i variable. To clarify just see the example of code - 



 i = 1;
 j = ++i;

 printf("i = %d, j = %d", i, j)
 
 // Output =>
 i = 2, j = 2



i++
i++ will increment the value of i variable then returns the original i variable. To clarify just see the example of code - 



 i = 1;
 j = i++;

 printf("i = %d, j = %d", i, j)
 
 // Output =>
 i = 2, j = 1

Look, in this example j is not incremented, j is the original i's value.


When we've to use i++ or ++i

This is a question I've brought from many people, when we've use i++ or ++i.
You've seen the difference of them. Now it's your choice. You can use any of them i++ or ++i. For a for loop, they works just same.
But as a programmer or in common programming ++i is always better than i++. ++i never goes wrong. See the performance issue part.

Performance issue i++ vs ++i

First need to tell for a small project theirs no difference between i++ or ++i.

But potentially i++ could be slower than ++i , Because i++ will create an extra copy and that's need a memory, which is not by ++i.

Why: See the example again

 
i = 1; //1
++i;  // 2

i = 1; //1
i++;  // 1


Look here,

  1. In first case, there is no temporary value to store, it just print the incremented value
  2. In second case i++, it's not printing the incremented value. It's store the value in another temp file. That is really unnecessary and takes memory.


And another thing, though i++ needs a temp variable, it's not any hard task for our computer today and in real life basically they are the same.
both the i++ or ++i containing file create the same object file and theirs no difference.
There is no compiler difference today between ++i or i++.

See a compiler object both i++ and ++i

After generating an assembler of both ++i and  i++ by this way,
$ gcc -c i++.c ++i.c
$ gcc -S i++.c ++i.c

Assembler output of both are the same, like -
$ md5 i++.s ++i.s
MD5 (i++.s) = 90f620dda862cd0205cd5db1f2c8c06e
MD5 (++i.s) = 90f620dda862cd0205cd5db1f2c8c06e

$ md5 *.o
MD5 (++i.o) = dd3ef1408d3a9e4287facccec53f7d22
MD5 (i++.o) = dd3ef1408d3a9e4287facccec53f7d22


But it's obviously better to use ++i over i++.

Conclusion on ++i and i++: 

Since it seems that i++ take a local variable copy and ++i don't, in today's computer can manipulate them same manner and theirs really don't performance issue.

Hopefully, your conflict has cleared now about ++i or i++. You can use both depending on your needs.



Tags:

Difference Between i++ and ++i and their performance issue, Which is better i++ or ++i, ++i is better than i++, increment i and i increment differences. i++ vs ++i.

Read More

Wednesday, September 20, 2017

Download C programming best books free as PDF

Download C programming best books free as PDF


See In Youtube What is inside these Books.




Book 1 - Practical C Programming:

Book Name : Practical C programming
Book Author : Steve Oualline
Book Category : C Programming
Book Edition : Third
Book Publisher : O'REILLY
Book Pages : 504
Book Size : 5 MB
Book Level : Intermediate Level C programming Book
Book Screenshot:

Download Book Free: Download Practical C programming Book Now [Click Skip Ad]



Book 2 - C Programming Tutorial:

Book Name : C programming Tutorial
Book Author :  Mark Burgess
Book Category : C Programming
Book Edition : Fourth
Book Publisher : K&R
Book Pages : 401
Book Size : 2 MBBook Level : Intermediate Level C programming Book
Book Screenshot:

Download Book Free: Download C programming Tutorial Book Now [Click Skip Ad]
Read More

Monday, September 18, 2017

UVA Online Judge solution 523 - Minimum Transport Cost - Solution in C++ - Volume 5

UVA Online Judge solution 523 - Minimum Transport Cost - Solution in C++ - Volume 5


UVA Online Judge Solution 523 - Minimum Transport Cost  | Volume 5
UVA Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=7&page=show_problem&problem=464

Problem Name: 523 - Minimum Transport Cost  solution
Problem Number : UVA - 523 - Minimum Transport Cost solution
Online Judge : UVA Online Judge Solution
Volume: 5
Solution Language : C plus plus

UVA Online Judge Solution, UVA OJ Solution list, UVA Problems Solution, UVA solver, UVA all problem solution list



UVA Solution 523 - Minimum Transport Cost Code in CPP:

#include <stdio.h>
#include <sstream>
#include <iostream>
#include <queue>
using namespace std;

int main() {
    int t;
    char s[505];
    int g[505][505], gv[505];
    scanf("%d", &t);
    while(getchar() != '\n');
    while(getchar() != '\n');
    while(t--) {
        gets(s);
        stringstream sin(s);
        int n = 1, x, y, i, j;
        while(sin >> g[1][n])
            n++;
        n--;
        for(i = 2; i <= n; i++)
            for(j = 1; j <= n; j++)
                scanf("%d", &g[i][j]);
        for(i = 1; i <= n; i++)
            scanf("%d", &gv[i]);
        while(getchar() != '\n');
        int pflag = 0;
        while(gets(s) && s[0]) {
            if(pflag)   puts("");
            pflag = 1;
            int st, ed;
            int dis[505] = {}, used[505] = {}, prev[505];
            sscanf(s, "%d %d", &st, &ed);
            for(i = 1; i <= n; i++)
                dis[i] = 0xfffffff;
            dis[st] = 0;
            queue<int> Q;
            Q.push(st);
            while(!Q.empty()) {
                x = Q.front(), Q.pop();
                used[x] = 0;
                for(i = 1; i <= n; i++) {
                    if(g[x][i] == -1)
                        continue;
                    if(dis[i] > dis[x]+gv[i]+g[x][i]) {
                        dis[i] = dis[x]+gv[i]+g[x][i];
                        prev[i] = x;
                        if(used[i] == 0) {
                            used[i] = 1;
                            Q.push(i);
                        }
                    }
                }
            }
            printf("From %d to %d :\n", st, ed);
            int stk[105], stkidx = 0;
            x = ed;
            while(x != st) {
                stk[stkidx++] = x;
                x = prev[x];
            }
            printf("Path: %d", st);
            for(i = stkidx-1; i >= 0; i--)
                printf("-->%d", stk[i]);
            if(st == ed) {
                printf("-->%d", ed);
                dis[ed] = gv[ed];
            }
            puts("");
            printf("Total cost : %d\n", dis[ed]-gv[ed]);
        }
        if(t)
            puts("");
    }
    return 0;
}


Tags: UVA Online Judge Solution, UVA OJ Solution list, UVA Problems Solution, UVA solver, UVA all problem solution list, UVA code in C, UVA code in C++, UVA solution in C, UVA solution, UVA OJ problems solution, UVA 523 - Minimum Transport Cost  solution, UVA online judge codes, UVA 523 - Minimum Transport Cost  problem 523 - Minimum Transport Cost solution, UVA Solution in C, UVA solution in C++, UVA 523 - Minimum Transport Cost  solution in java

Read More

Wednesday, July 19, 2017

Download Tutorials point latest offline documentation 2017 - Free download link

Download Tutorials point offline documentation latest version 2017:


Tutorials point is one of the most big site for tutorials of all types like HTML, CSS, Javascript, PHP, C Programming, C++ programming, Java Programming, Python Programming and so all. Get the TutorialsPoint offline documentation today and learn all of the tutorials of Tutorials Point.


Download Tutorials point latest offline documentation just in one click:

See a demo video to download Tutorials point offline documentation


Why Offline Documentation: 

Offline documentation gives you the better opportunity to work when you have no internet and this is why it is a very good idea to use it,


Download link : Download Tutorials Point latest offline documentation 2017
Size: 129 MB
Label : Tutorials Point Offline Documentation
Mirror Download link : Download Tutorials Point latest offline documentation 2017
[Note: ]
Please click SKIP when adf.ly advertise appears.

Download Tutorials point latest Offline Documentation


[Note: ]
Please click SKIP when adf.ly advertise appears.




Tags:
HTML Offline Documentation, Bootstrap Offline Documentation, CSS framework, C Plus Plus Offline Documentation, PHP Framework Documentation, Javascript Framework Documentation, Tutorials Point offline documentation, Tutorials point latest offline documentation, Tutorials Point Documentation, Tutorials point Free Documentation, Tutorials point All documentation, Tutorials point Full docs, Download Tutorials point latest offline documentation 2017 - Free download link



Read More

Saturday, July 15, 2017

Modern Digital Electronics By R. P Jain second Edition Free PDF Download Link

Modern Digital Electronics By R. P Jain second Edition Free PDF Download Link

Book Name - Modern Digital Electronics
Book Author Name - R. P Jain
Book Page - 500
PDF by - taking image
Book Size - 53 MB
Download Link of Modern Digital Electronics - http://adf.ly/1nQw0i - (Click Skip Ad Button Must)

See demo on Youtube:



Book Front page screenshot:






Tags:

Modern Digital Electronics By R. P Jain second Edition Free PDF Download Link, Modern Digital Electronics Book pdf download link, Modern Digital Electronics ebook download, Modern Digital Electronics.pdf free, Modern Digital Electronics By R P Jain book free download, Rp Jain book download, Electrical book download, Digital electronics pdf, Modern Digital Electronics second edition by R.P jain , Modern Digital Electronics pdf free download, Modern Digital Electronics ebook download link.


Read More

Saturday, May 13, 2017

URI Solution 1213 Ones - Solution in C, C++

URI Solution 1213 Ones - Solution in C, C++


URI Online Judge Solution  1213 Ones | Data structures
URI Main Problem Link - 1213 Ones https://www.urionlinejudge.com.br/judge/en/problems/view/1213

Problem Name: URI Problem 1213 Ones
Problem Number : URI Problem 1213 Ones Solution



 Online Judge : URI Online Judge Solution
Level: Data structures
Solution Language : C, C plus plus

URI Solution 1213 Ones - Solution in C, C++

URI Solution 1213 Ones Code in C:

#include <stdio.h>
 
int main(int argc, char const *argv[])
{
 long long int n, l, c;
 
 while(scanf("%lli", &n) == 1){
  l = 1;c = 1;
 
  while(l % n != 0){
   l = (10 * l + 1) % n;
   c++;
  }
 
  printf("%lli\n", c);
 }
 
 return 0;
}


URI Solution 1213 Ones Code in C++:

#include <cstdio>
 
using namespace std;
 
int main(int argc, char const *argv[])
{
 long long int n, l, c;
 
 while(scanf("%lli", &n) == 1){
  l = 1;c = 1;
 
  while(l % n != 0){
   l = (10 * l + 1) % n;
   c++;
  }
 
  printf("%lli\n", c);
 }
 
 return 0;
}



Tags: Uri solve , Uri solution, URI oj Solve, URI Online Judge Solution list, URI 1213 solution in C, URI 1213 solution in C++, URI Ones Solution, URI 1213 code in C, URI 1213 code in C++

Read More

URI Solution 1212 Primary Arithmetic - Solution in C, C++

URI Solution 1212 Primary Arithmetic - Solution in C, C++


URI Online Judge Solution  | Mathematics
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1212



 Problem Name: URI Problem 1212 Primary Arithmetic
Problem Number : URI Problem 1212 Primary Arithmetic Solution
Online Judge : URI Online Judge Solution
Level: Mathematics
Solution Language : C, C plus plus

URI Solution 1212 Primary Arithmetic - Solution in C, C++


URI 1212 solution in C language/ URI Primary arithmetic code in C:

#include <stdio.h>
#include <string.h>

long NumCarryAdd(long n1, long n2 )
{
    long a,b,c,t;
    c = 0;
    t = 0;
    while(1)
    {
        a=n1%10;
        b=n2%10;
        n1=n1/10;
        n2=n2/10;
        if((a+b+c)>=10)
        {
            t++;
            c=1;
        }
        else c = 0;
        if(n1==0 && n2==0)break;
    }
    return t;
}

int main()
{
    long x, y, carry;
    while(1)
    {
        scanf("%ld %ld", &x,&y);
        if(x == 0 && y == 0) break;
        carry = NumCarryAdd(x, y);
        if(carry == 0) printf("No carry operation.\n");
        else if(carry==1)printf("1 carry operation.\n");
        else printf("%ld carry operations.\n", carry);
    }
    return 0;
}


URI Solution 1212 Primary Arithmetic Code in CPP:

#include <iostream>
using namespace std;

int main(int argc, char const *argv[])
{
 long int a, b, _a, _b, c, carry, result;

 while (cin >> a >> b && (a || b))
 {
  carry = c = 0;
  
  while (a != 0 || b != 0)
  {
   _a = a % 10;
   a = a / 10;
   _b = b % 10;
   b = b / 10;

   result = _a + _b + c;
   if (result >= 10){
    c=1;
    carry += 1;
   }
   else
    c=0;
  }
  
  if (carry == 0){
   cout << "No carry operation." << endl;
  }
  else if (carry == 1){
   cout << carry << " carry operation." << endl;
  }
  else if (carry > 1){
   cout << carry << " carry operations." << endl;
  }
 }
 return 0;
}


Tags: Uri solve , Uri solution, URI oj Solve, URI Online Judge Solution list URI 1212 solution, URI Primary Arithmetic solution, URI 1212 Primary Arithmetic Solution, URI 1212 code in C, URI 1212 solution in C++

Read More

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.