Thursday, 29 June 2017

Can we display "Hello World" without using a semicolon in C ?

Well the answer is YES!. But to understand this we need to cover some basics of ‘function’.
Don’t worry I am not going to explain the basics of function. As I assume you know it. I am sure you are also familiar with the term “return” which is frequently used inside the function. We also know that every function must return a value. This statement is the key to solve this puzzle. Yes you heard it right. Having said that, Lets understand what kind of values are returned by most frequently used functions? For example, printf()

Whenever we use printf() function, what we expect is the Output display on the screen. We hardly care about what kind of value does it returns. Let’s check it out.

main()
{
int valueReturned = 0;
valueReturned = printf(“Welcome to Programming!”);
printf(“\n %d”, valueReturned);

}

What do you think will be the output? “Welcome to Programming!” is going to be displayed on the screen for sure. But I am interested in the value of the variable named, valueReturned. If you run this program in any C compiler it would show the output as given below
                      Welcome to Programming!
                      23
Well, This 23 is nothing but the length of the string enclosed within the double quotes which we usually see on the screen. Which means, something like printf(“%d”, printf(“Hello World”)); will give an output like “Hello World11”. Further, to enhance your learning, you should check the output for the statements like
printf(“%d”, printf(“\n Hello World”)); printf(“%d”, printf(“\t Hello World”)); etc. to understand whether '\n' counts as 0, 1 or 2 characters?

Now if you have understood this, we are half done. Next thing which we need to understand to solve this puzzle is the conditional statement “if()”. Relax! I am not going to start talking about the basic functionality of the “if” keyword here. I assume you guys know this. What I wanted to discuss here is, in the if() section, Some people think that, if you pass 1 and 0 it is evaluated as True and false respectively. In fact, Any Non Zero value passed inside any conditional statement evaluates to true in C language. For example, you must have seen the example of infinite loop in most of the text books is written as “while(1){}”.

We are done with theory part of the puzzle, now it’s time to write the code.

main()
{
    if(printf(“Hello World”))
       {
       }
}

If you run this program, It will not throw any compilation error and will display the text
Hello World” on your screen.




Tuesday, 27 June 2017

What will be the range of an integer data type of size 3 Bytes or 5 Bytes??

In C programming or any other programming laanguages, there is a term called range of the data type say “int”. If I talk about the C programming specifically, the size of an int data type is 2 bytes or 4 bytes depending upon the operating system used. Let’s assume the size of an int data type is 2 bytes for this moment. What should be the range of int now?

Well, if we talk about signed int, then its between -32768 to 32767. It’s something that we read in a textbook or any other source. How is it calculated? Let’s find it.

As we know, 1 Byte = 8 bits. Which means 2 Bytes = 16 bits. So the Maximum number this data type can store is 216. Which equals to 65535. Let’s understand this. We said it’s 16 bits, means we can have two values i.e either 0 or 1 for each bit.

0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1

That is why the range of an unsigned int lies between 0 – 65535. If we talk about the signed int range, then it’s -215 to 215 – 1. As we reserve the left most bit for the sign. So we are left with only 15 bits for storing the values.

So whenever we need to calculate the range of any integer data type, we need to get the size of that data type so that we can calculate the total number of bits. Once the total number of bits is available we can calculate the range(unsigned) by simply 0 - 2(total number of bits). Similarly, the signed range of that data type would be: - 2(total number of bits – 1) to 2(total number of bits – 1) -1.

Why that -1 ?? Well it’s because 0 is treated as positive number. For example, if we have to divide 10 numbers in to equal parts the division would be like....

                     -5   -4   -3   -2   -1   0   1   2   3   4

So let’s calculate the range of a hypothetical integer data type which takes 3 Bytes in memory. 3 Bytes means 3 * 8 = 24 bits.

So the unsigned range will be : 0 – 224
And, signed range will be : - 223 – 223 – 1


Hope you can calculate the range of integer data type of any size. 

Sunday, 18 June 2017

How compilers treat the operators like "++" and "--"


The operators like pre-increament(or decreament) and post increament(or decreament) is very commonly used operators for the programmers. It is widely used in the loop. I know, it’s pretty simple to understand. Well, It’s not restricted to be used for the loop only. It can be used for a simple instructions like
++i * ++i * --i * i++ ....
It’s tricky to get the correct value of this operation. And, It totally depends upon the compiler you are using. I always used to get stuck in thses kind of operations. But today I would like to share my understanings with you guys.
Okay!, Lets start with the most popular language, i.e., C Language and see how C compiler treats this ++ and – opeartor when used for the calculation.
Let me write a small piece of code
main()
{
int x = 3, y, z;
y = ++x * ++x * ++x;
printf(“The Value of y = %d”, y);
x = 3;
z = x++ * x++ * x++;
printf(“\n The Value of z = %d”, z);
}
Any Guesses? Well, The value of ‘z’ is not hard to get but the value of ‘y’. The output of the above written code is :
The Value of y = 216
The Value of z = 27
Surprised with the value of y? As I mentioned earlier, it totally depends upon the compilers, but in most of the C compilers you will get the same value.
Okay, let me tell you the logic now. Whenever the “++” or “--” operators are used for the operations like in the above code. It’s value are pre-calculated. Further, the calculated value used for the rest of the operations.
e.g.,
x = 3;
y = ++x * ++x * ++x;
As we can see that, the “++” operator has been used three times here, so the value of x would be
x = x+3(only for pre-increament operator)
i.e, x = 6;
now the y = 6 * 6 * 6, i.e 216.

Well, The compilers like Java or JavaScript will give a different output, In Java or JavaScript, the output would be simply 4 * 5 * 6 = 120. It’s perhaps the C language only who treats these operators in this way. Anyways, what if there is a mixture of pre-increament and pre-decreament operator? Something Like,  
int i = 2, j;

j = --i * ++i * ++i * ++i * ++i * --i;

It’s pretty simple, “--” has been used twice while “++” used for four times. So basically it’s two times “++”. Yes, you can cancel out each “--” with a “++” and  vice versa.

now the final value of i is

i = i+2, i.e., 4

j = 4 * 4 * 4 * 4 * 4 * 4;

j = 4096.

In Short, 
Remember, since "++" or "--" is having the highest priority among all the operators so we need to pay attention towards this operator. Calculate the final value of the variable, by counting the number of "++" and "--" associated with the variable and cancelling out each "++" with "--" and vice versa. Preceed with this final value to perform the rest of the calculation. 
 




Sunday, 11 June 2017

JavaScript : Difference between Null and Undefined

The undefined value is a primitive value used when a variable has not been assigned a value. The null value is a primitive value that represents the null, empty, or non-existent reference. When you declare a variable through var and do not give it a value, it will have the value undefined. By itself, if you try to WScript.Echo() or alert() this value, you won't see anything. However, if you append a blank string to it then suddenly it'll appear:
var s;
WScript.Echo(s);
WScript.Echo("" + s);
You can declare a variable, set it to null, and the behavior is identical except that you'll see "null" printed out versus "undefined". This is a small difference indeed.
You can even compare a variable that is undefined to null or vice versa, and the condition will be true:
undefined == null
null == undefined
They are, however, considered to be two different types. While undefined is a type all to itself, null is considered to be a special object value. You can see this by using typeof() which returns a string representing the general type of a variable:
var a;
WScript.Echo(typeof(a));
var b = null;
WScript.Echo(typeof(b)); 
Running the above script will result in the following output:
undefined
object 
Regardless of their being different types, they will still act the same if you try to access a member of either one, e.g. that is to say they will throw an exception. With WSH you will see the dreaded "'varname' is null or not an object" and that's if you're lucky (but that's a topic for another article).
You can explicitely set a variable to be undefined, but I highly advise against it. I recommend only setting variables to null and leave undefined the value for things you forgot to set. At the same time, I really encourage you to always set every variable. JavaScript has a scope chain different than that of C-style languages, easily confusing even veteran programmers, and setting variables to null is the best way to prevent bugs based on it.
Another instance where you will see undefined pop up is when using the delete operator. Those of us from a C-world might incorrectly interpret this as destroying an object, but it is not so. What this operation does is remove a subscript from an Array or a member from an Object. For Arrays it does not effect the length, but rather that subscript is now considered undefined.
var a = [ 'a', 'b', 'c' ];
delete a[1];
for (var i = 0; i < a.length; i++)
WScript.Echo((i+".) "+a[i]); 
The result of the above script is:
0.) a
1.) undefined
2.) c 
In short, JavaScript will never set anything to null, that's usually what we do. While we can set variables to undefined, we prefer null because it's not something that is ever done for us. When you're debugging this means that anything set to null is of your own doing and not JavaScript. Beyond that, these two special values are nearly equivalent.

Saturday, 3 June 2017

5 Mistakes to Avoid When Building Your Mobile App



Mobile apps are extremely popular at the moment, and they’re paving the way for all kinds of new and exciting business ideas. The problem, especially for many of the smaller-sized bussiness, an individual or the freelancers is to figure out the right approach.

 

1. Building for Multiple Platforms at Once

Let’s face it, with over one million apps on both the Google Play and Apple App Store, you are playing in a very competitive space.
Avoid doubling your engineering costs and focus on building on one platform first. This also helps get your minimum viable product (MVP) out in the app store as soon as possible.
In addition, if you do launch on both platforms at once and need to make any changes to design and/or functionality, then you will need to do it on both places which adds more development time and cost.
It’s better to finalize an app on iOS and have a couple of iterations before porting it to Android (or vice versa).
Remember that Instagram had 30 million users already on iOS before they even launched their Android version.


2. Having Bloated Features

Now that you have picked your app store of choice for the initial launch, it’s important to have a core set of features as your MVP. With your first version, you want to prove the core hypothesis of your app to see if the market is willing to adopt it.
Good user experience is about doing more with less.
If you have an existing web service, don’t try to condense the online experience into the mobile screen. It’s important to rethink your entire user flow and interactions on mobile and not replicate the online experience.
In addition, while it’s important to launch with just a core set of features, remember not to rush development and release a buggy app. Mobile users are unforgiving and will leave 1-star reviews if your app is buggy. This rocky start is very difficult to recover from.


3. Skimming on User Experience

Apple has set the bar with its elegant product design and user experience. You can hand over your iPhone or iPad to a toddler and they will immediately know how to use it.
The mobile user has different expectations than the one on the web. The mobile experience needs to be self-describing and intuitive. While the online user may put up with poor user experience and design, a mobile user will quickly give up on your app if it’s too difficult to use.
In fact, 26% of the apps are only opened once and never use it again, and another 48% are opened 10 times or less. Therefore, you need to have an immediate “wow” factor upon the user launching the app.


4. Trying to be the beta tester for your own app.

“Why have someone else beta test your app when you can do it yourself?”
If you’ve ever asked this question while developing an app, you’ve probably been burned by the outcome. There’s a reason why beta testers are important: They offer valuable outside perspective that will help to catch issues with your app.
It’s not just the bugs that matter, either -- some of these ideas can be crucial for making your app user-friendly. For instance, maybe your in-app purchases aren’t communicated clearly enough, or maybe your use of advertisements is making the entire experience feel a bit jarring. Because you built the app this way, it’s harder for you to be able to pinpoint these high-level flaws.
Use app-analytics tools to see how your testers are using the app. The more people you can have beta test your app outside your own office, the more prepared you’ll be to send your app out into the real world.


5. Marketing After Submitting App

It’s important to start marketing your app as early as possible. Don’t wait until submitting the app to the App Store to start your press outreach. According to the Experts of this domain, You should contact the media around 2-4 weeks before you plan to launch.
Before sending emails, research your favorite technology blogs and look for journalists who have written about a similar app. When sending your emails, make sure to keep them short, personal, and include a few details about what makes your app different.
Include a link to a screenshot or video so the blogger can quickly get a sense of what your app does. At the end of the email ask if they’d like to know more or perhaps try out the app before it goes live.