Introduction To Programming

Why programs ? Programming is nothing but making the computers think the same way a human thinks. Programs are made for obtaining a specific solution which can even be solved by humans which when solved by us may consume time..

Friday, April 30, 2010

Predict the output

extern int a;
int ss();
int main()
{
int a=10;
ss();
return printf("%d",a);
}
int ss()
{
return printf("%d",a);
}
int a=20;
Answer:
2010
1020
1010
Compilation Error

Monday, April 26, 2010

Predict the Output:

main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("shark selva");
else
printf("Matrix Developer");
}



shark selva
Matrix Developer

Difference between a string copy (strcpy) and a memory copy (memcpy)?

What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?


why??

why n++ executes faster than n+1?



Sunday, April 25, 2010

Is these two programs same?

for (i=0;i<5;i++)
{
if(i%3==0)
continue;
}

i=0;
while(i<5)
{
if(i%3==0)
continue;
i++;
}

Answer:

Yes
No



Saturday, April 24, 2010

Additon without Arithmetic Operators:

Here is the program which use bit wise operator and perform the addition operation. There is no arithmetic operator is used in this program.

int main()
{
int a,b,sum,carry;
printf("Enter the values");
scanf("%d %d",&a,&b);
sum=a^b;
carry=a&b;
while(carry!=0)
{

Program without Header File

is it possible to run the program without header file?  yes, it is possible.  consider the following program.

int main()
{
printf("hi");
return 0;
}
 It will work perfectly ,if you save the file.  But the concept is that while compiling itself ,compiler includes stdio.h header file automatically. 

Predict the Output:

int main()
{
fprintf(stdout,"Hello");
return 0;
}
 Answer:


Error,stdout is undeclared
Hello will be printed in console
Hello will be print in stdout.c file

Will it work?

#include<string.h>
int main()
{
printf(strcat("www.newtech4u.co.cc","!");
return 0;

}

exit Function:

This article will teach you what the exit function does.


Definition of exit Function:
exit function terminates the program process. It is called as "exit(error_status)"
 consider this following program:
 #include<stdio.h>
#include<stdlib.h>

Difference between Normal function and Macro Funcion

Normal function is defined :
return_type function_name(arguments)
{
//coding
}
Macro function:
#define funtion_name(arguments) coding

Difference:
while compiler expanding the code, the macro function is replaced in called place, but normal function is just called by . 


Macro function example source code and expanded code:

Source Code:
#define tech() printf("hi")
int main()

Run the coding after exiting main function

Do you think that it is possible to run the code after exiting main function? Yes ,it is possible to run the codes after exiting main function also.

Consider this Simple Program:
#includ<stdio.h>
#include<stdlib.h>
void after_main()
{

Pointer vs Array

Let you teach what is difference between pointer and array. Firs of all we should know the definition of pointer and array.

Pointer:
Pointer is a variable that capable of storing the address
Array:
Array is collection of same elements

Difference between #include and #include "stdio.h"

Many of you confused with this two method of specifying the include files. This article will teach you what the difference between these two is.

#include <stdio.h>

This method of specifying is used to include the standard header files.

Sunday, April 18, 2010

Predict The Output:

int main()
{
int *p=(int *)1000;
*p=2;
printf("%d",*((int*)1000));

return 0;
}

Predict The Output:

int main()
{
char a[]="shark";
(*a)++;
printf("%s\n",a);
printf("%s",a+1);
return 0;
}

Output:
thark
hark

Predict The Output:

int main()
{
return printf("shark ");
}
int x=main();

Don't think that it will result in compilation error. It will run perfectly and prints "shark shark".

Output:
shark shark

Predict the Output

int main()
{
int a=1;
a+=a++;
printf("%d",a);
a+=++a;
printf("%d",a);
return 0;
}

Output:
3 8

Logic:
a+=a++ is equal to a=a+a++;
watch out the value of 'a' in this expression.
a=a + a++
3  1   1
a+a=2 and the post increment will increment the value of 'a' so it will result in a=3.(to understand increment operator see this post also Lparts,Pre and post,Post 18).

Now we will consider the second operation i.e., a+=++a;. This expression is equal to
a=a+ ++a;
This expression is manipulated as follows:
a = a+  ++a;
8   4     4    
Pre increment will increment the value of a first so 'a' has now 4. and a+a is 8 is assigned to a. so a=a+a=8.

What is Null?

Two type of Null , "NULL pointer","NULL character. NULL means "nothing".
NULL pointer usually assigned to pointers. This will make pointer to point nothing i.e, pointer reference to no variable.
NULL character('\0') usually added automatically at the end of each string used in c program. It defines end of string.

Predict the Output

#define tech(a,b) a##b##a
int main()
{
if(printf("%d",tech(4,0)))
{
}
return 0;
}

Output:
404

Read about Macro

Saturday, April 10, 2010

74

Predict the output:
int main()
{
int d;
int s();
d=s();
}
s()
{
int i=0,j=i<3,k=j<2>=i;
return i++*++k-j++;
}