Showing posts with label M.Tech. Show all posts
Showing posts with label M.Tech. Show all posts

Monday, September 5, 2016

Different variation of #define

1.
#include<stdio.h>
#define SQUARE(t) t*tvoid main()
{
      int n=8, Res;
     Res = 64/SQUARE(t);
     printf("%d",Res);
}
Result will be 64 . why?
because the statement Res=64/SQUARE(t); will be converted to  Res=64/8*8;
Res=64/8*8
     = 8*8=64.
Hence the preprocessor #define only substitute the statement not calculation.
Then what can I do , If I want to result as 1. The program should be
#include<stdio.h>
#define SQUARE(t) (t*t)void main()
{
      int n=8, Res;
     Res = 64/SQUARE(t);
     printf("%d",Res);
}
Now the result will be
Res=64/(8*8)
      =64/64 = 1
Again if program will be
#include<stdio.h>
#define SQUARE(t) (t*t)
void main()
{
      int n=8, Res;
     Res = 81/SQUARE(t+1);
     printf("%d",Res);
}
What will be the result, if you are thing about 1 then it is not right , But why? Now see
Res=81/SQUARE(t+1)
     = 81/(8+1*8+1)
     =81/(8+8+1)
     =81/17
      =4.76
=  4 (Because integer will display only integer part)
then what are the solutions? The solution will be
#include<stdio.h>
#define SQUARE(t) ((t)*(t))void main()
{
      int n=8, Res;
     Res = 81/SQUARE(t+1);
     printf("%d",Res);
}
2. Now guess what will be the result of
#include<stdio.h>
#define CUBE(t) t*t*t
void main()
{
      int n=5, Res;
     Res = 125/CUBE(t);
     printf("%d",Res);
}
???????????????????/
Your queries are always welcome.
3.
#include<stdio.h>
#define print(Num) printf("%d",Num);
int main()
{
    int Number=10;
    print(Number);
    return 1;
 }
It will display 10 , So Now you can print integer variable by own print command
4.


Sunday, August 28, 2016

Logical Components of an Android Mobile Application Development

Logical Components of an Android Mobile Application Development

 When you want to create a dynamic application then you have to require some important logical components of an Android application. There are four logical component of the Android Mobile Application Development:
1. Activity: Activity is one of the key logical component of the Android Mobile Application Development. It is the basis of User Interface of the app and makes the foundation of User Interface. User Interface contains visual elements , layout elements , resources and many more things.
Programmed component of the Used Interface which is programmed using java is an Activity and event handling. For example : Music is playing in background and in front you are using the browser.

2. Service: Service is another key component of an Android application. It always runs in the background and does not have a user interface. But UI is associated with it to interact with the service. In the music player, user need the UI to shuffle the songs or select the songs but for listening it not required to be in front of the mobile. User may use another app while listening the songs.

3. Broadcast Receiver: While you are using the mobile, there may be lots of announcement in your mobile related to low battery, download complete, incoming call, incoming SMS, availability of WI-FI Spot are initialed by the system. Some announcements are initiated by the app itself to let the other app understand. For Example: After completion of the download and is available of used.

4. Content Provider:  The data or content of the mobile app and is accessible across apps is the important aspect of mobile app development. However , due to security, any app required permission to access other app data . These data sharing after taking permission is done by using content provider. For example: for call a person whose detail is already saved in the contacts app, then contact app work as a content provider for calling , email and message app.
 

Video for the concept of Array and pointers

Example Program of Array and Pointers (Video)

https://www.youtube.com/watch?v=lT5D08ofRBQ

Some Important conceptual output based questions of Arrays and Pointers in C lnaguage

Some Important conceptual output based questions of Arrays and Pointers in C language 

1. 
void main()
{
   int Blog[]={1,2,3};
   printf("%d %d %d",Blog[1],Blog[2],Blog[3]);
}

Output: 2 3 0

Explanation: Here Blog[0],Blog[1] and Blog[2] will be initialized with 1,2 and 3 respectively. and rest are initialized with 0.

2.
void main()
{
   int Blog[]={33,44};
   printf("%x",Blog);
 }

Output: Base address of Blog

Explanation: The array name always holds the base address of an array. If we print *Blog then output will be the first value.

3.void main()
{
  int Blog[4]={22,33,44,55},*ptr,T;
  ptr=Blog;
  T=++(*ptr);
  printf("%d %d",*ptr,T);
 }

Ans: 23 23

Exlanation: *ptr points to the first element of an array Blog. After ++(*ptr) , the value 
of first element is increased by 1 that is 23 and also updated to the array. Hence the output will be 23 23.

4.
void main()
{
  int Blog[4]={22,33,44,55},*ptr,T;
  ptr=Blog;
  T=*(ptr++);
  printf("%d %d",*ptr,T);
 }

Ans: 33 22

Explanation: *ptr points to the first element of an array Blog. After *(ptr++), the pointer ptr points to next element that is second element of array but due to post increment the variable T contains the first element of an array Blog.

Tuesday, August 23, 2016

Variable Declaration and Datatype in C language with their uses

Variable Declaration

The memory area used for storing the input data or intermediate data , is called variable.
There are some rules to declare the variables in C language:
1. Must be start with alphabet.
2. Special character is not allowed except _(Underscore).
3. Variable may be alphanumeric.
4. Variable name must be different from keywords used in C language like printf, scanf,eof etc.

The syntax for variable declaration is 
1. <datatype><space> <variablename>
2. <datatype><space> <variablename>=<value>

for example: int x;
int Num=10;
char str;
char str[45];

Datatype used in C language

A datatype is used to instruct the compiler that what type of data will be stored in variable. Different type of datatype are used in C language is:
1. int(2 to 4 byte)
2. float(4 Byte)
3. cha(1 byte)
4. double(8 byte)
5. long(4 Byte)

int and long datatype is used to store the integer , float and double are used to store the real values and char is used to store the character values.

Example:
int a,b;
char ch;
float Num;


Monday, August 22, 2016

Pattern Design in C Language

Write a program to draw the following pattern:

*
**
***
****
*****

void main()
{
     int i,j;
     for(i=1;i<=5;i++)
     {
           for(j=1;j<=i;j++)
                printf("*");
       printf("/n");
      }
}


Sunday, August 21, 2016

Tips for Technical Interview in IT industry

Tips for Technical Interview in IT industry

  1. Prepare for a short introduction including the technical project which are genuinely done by you.
  2. Go through the website of company and get the information about company. for example: the company work for which domain primarily etc.
  3. Ask to seniors if any already working in the company about the technologies used by the company.
  4. Prepare yourself for the fundamentals of programming and algorithms because programming is the backbone of IT company.
  5. Prepare yourself comfortable upto average level(Concepts of classes,functions,datatypes,looping,conditional statement) for any one programming languages or tool.
post your query related to technical interview.

String in Java

Strings in Java

1. int n;
char chr;
String st1=”Rakesh Roshan”;
n=st1.indexOf(‘e’);
chr=st1.charAt(5);

what will be the value of n and chr?

2. int n;
String str1=”Rakesh”;
String str2=”Roshan”;
n=str1.compareTo(st2);

what will be the value of n ?

Different way to access array elements

Do you know there are many ways to access the elements of array.
int Num[10];
for(int i=0;i<10;i++)
    printf("%d%d%d%d",Num[i],i[Num],*(Num+i),*(i+Num));
Here all the format will give the same result that is every element of Array.

Saturday, August 20, 2016

Malloc and Calloc

Difference between Malloc() and Calloc()
1. malloc() takes one argument while calloc() takes two argument
2. malloc() does not initialize the allocated memory while calloc allocated memory intialized with 0.
3. Both are used for dynamic memory allocation.
4. malloc is faster than calloc
5.Example: int *p=(int *)malloc(sizeof(int));
                   int *p=(int *)calloc(10,sizeof(int));

What will be the output of -1<<4 in C language?
Ans: The binary equivalent of -1 in 2 Byte is 1111 1111 1111 1111.
So after 4 left shift the result will be 1111 1111 1111 0000.
Hence the output will be fff0  in Hexadecimal format.

This question is very common for the placement exams of various company.

Android Mobile Application Development

Android Mobile Application development is very easy. Mobile Application Development can be done by any body who have a basic programming knowledge of Java, XML, HTML. The tools required to develop a Mobile Application are:
1. Eclipse or Android Studio
2. Android SDK
3. jdk 1.7 and above

In next post I will give you step by step procedure to develop first mobile application.

Preprocessor

Preprocessor is just the tools for text substitution. Preprocessor instructs the C compiler to do some work or processing which is to be done before compilation. Preprocessor is always start with #.Type of preprocessor are:
1. File Inclusion : #include
2. Macros: #define, #undef
3. Conditional : #if, #ifdef, #ifndef,#else, #elif,#error,#pragma,#endif

hidden facts of printf() statement

printf() statement is used to print the message as well as values of the variable, but some hidden facts for printf() statements are:

1. The return type of printf() statement are integer i.e the number of character printed by the printf statement.
     Example:  printf("%d","printf("Hello")); will print 5
2. If we do not provide variable name with the printf statement like printf("%d"); , Then the printf statement print the value which is in top of the stack of the memory.
    Example:
    void main()
    {
         int a=100,b=78;
         printf("%d");
}
you feel that it is the wrong or syntax error, but it will print the latest value which is on top of the stack that is 78

Friday, August 19, 2016

Macro

Macro is not a function , it is used as a substitution. #define just replace SQUARE(8) by 8*8 rather than 64.