Tuesday, June 28, 2011

C questions........

(q)What will be output of following c program?

int *call();
void main(){
int *ptr;
ptr=call();
clrscr();
printf("%d",*ptr);

}
int * call(){
int x=25;
++x;
return &x;
}


Output: Garbage value
Explanation: variable x is local variable. Its scope and lifetime is within the function call hence after returning address of x variable x became dead and pointer is still pointing ptr is still pointing to that location.

Solution of this problem: Make the variable x is as static variable.

In other word we can say a pointer whose pointing object has been deleted is called dangling pointer.


Hide

4. What is wild pointer in c ? Answer


A pointer in c which has not been initialized is known as wild pointer.

Example:

(q)What will be output of following c program?

void main(){
int *ptr;
printf("%u\n",ptr);
printf("%d",*ptr);

}

Output: Any address
Garbage value


Here ptr is wild pointer because it has not been initialized.
There is difference between the NULL pointer and wild pointer. Null pointer points the base address of segmentwhile wild pointer doesn’t point any specific memory location.



Hide

5. What are merits and demerits of array in c? Answer



(a) We can easily access each element of array.
(b) Not necessity to declare two many variables.
(c) Array elements are stored in continuous memory location.

Demerit:
(a) Wastage of memory space. We cannot change size of array at the run time.
(b) It can store only similar type of data.



Hide

6. Do you know memory representation of
int a = 7; ? Answer



Memory representation of:

signed int a=7; (In Turbo c compiler)
signed short int a=7 (Both turbo c and Linux gcc compiler)
Binary equivalent of data 7 in 16 bit: 00000000 00000111
Data bit: 0000000 00000111 (Take first 15 bit form right side)
Sign bit: 0 (Take leftmost one bit)

First eight bit of data bit from right side i.e. 00000111 will store in the leftmost byte from right to left side and rest seven bit of data bit i.e. 0000000 will store in rightmost byte from right to left side as shown in the following figure:







Hide

7. What is and why array in c ? Answer


An array is derived data type in c programming language which can store similar type of data in continuous memory location. Data may be primitive type (int, char, float, double…), address of union, structure, pointer, function or another array.
Example of array declaration:
int arr[5];
char arr[5];
float arr[5];
long double arr[5];
char * arr[5];
int (arr[])();
double ** arr[5];



Array is useful when:
(a) We have to store large number of data of similar type. If we have large number of similar kind of variable then it is very difficult to remember name of all variables and write the program. For example:

//PROCESS ONE
void main(){
int ax=1;
int b=2;
int cg=5;
int dff=7;
int am=8;
int raja=0;
int rani=11;
int xxx=5;
int yyy=90;
int p;
int q;
int r;
int avg;
avg=(ax+b+cg+dff+am+raja+rani+xxx+yyy+p+q+r)/12;
printf("%d",avg);
}
If we will use array then above program can be written as:

//PROCESS TWO
void main(){
int arr[]={1,2,5,7,8,0,11,5,50};
int i,avg;
for(int i=0;i<12;i++){ avg=avg+arr[i]; } printf("%d",avg/12); } Question: Write a C program to find out average of 200 integer number using process one and two. (b) We want to store large number of data in continuous memory location. Array always stores data in continuous memory location. (q) What will be output when you will execute the following program? void main(){ int arr[]={0,10,20,30,40}; char *ptr=arr; arr=arr+2; printf("%d",*arr); } Advantage of using array: 1. An array provides singe name .So it easy to remember the name of all element of an array. 2. Array name gives base address of an array .So with the help increment operator we can visit one by one all the element of an array. 3. Array has many application data structure. Array of pointers in c: Array whose content is address of another variable is known as array pointers. For example: void main(){ float a=0.0f,b=1.0f,c=2.0f; float * arr[]={&a,&b,&c}; b=a+c; printf("%f",arr[1]); } Hide 8. Why we use do-while loop in c? Also tell any properties which you know ? Answer It is also called as post tested loop. It is used when it is necessary to execute the loop at least one time. Syntax: do { Loop body } while (Expression); Example: void main(){ int num,i=0; clrscr(); do{ printf("To enter press 1\n"); printf("To exit press 2"); scanf("%d",&num); ++i; switch(num){ case 1:printf("You are welcome\n");break; default : exit(0); } } while(i<=10); getch(); } Output: 3 3 4 4 If there is only one statement in the loop body then braces is optional. For example: (a) void main(){ double i=5.5678; clrscr(); do printf("hi"); while(!i); getch(); } Output: 3 3 4 4 (b) void main(){ double i=5.63333; clrscr(); do printf("hi"); while(!i); getch(); } Output: hi (c) void main(){ int x=25,y=1; do if(x>5)
printf(" ONE");
else if(x>10)
printf(" TWO");
else if(x==25)
printf(" THREE");
else
printf(" FOUR");
while(y--);
getch();
}

Monday, March 21, 2011

Success

What is Success..............
One ex. Sachin Tendulkar failed in 10th std. but now First chapter of 10th std textbook is on Sachin Tendulkar..This is Success means U can do anything but try to be perfect in that profession or any respective field.U need to have a kind of content,to feel fresh working in that field.Try to work in such a profession in which u are interested.Money is also important ,otherwise U will not have money at your old age.Have some plans according to that.
There is one saying about Success by Abraham Likon
"Always bear in mind that your own resolution to succeed is more important than any other."
Means U should be very desperate for Success.......Selfbelief is also very important .
Wish u all the very best guys...............

Sunday, March 20, 2011

India's Allround win Vs WestIndies

India win by a allround performance by 80 runs.Yuvraj Singh's knock of 123 0f 113 balls & in bowling he took 2 wickets.Bowling improved a little bit from last 5 matches.R Ashwin played a very vital role in the begining & Harbhajan at the other end.
Zaheer took wicket of Smith in superb form .This was the turning point of the match & after the wicket of Pollard by Harbhajan ,India's came back in the match.After that wickets continue to fall regularly & this work is done by Zaheer & Yuvraj.
We have to play with the same team against Australia with Ashwin,Zaheer,Harbhajan,Shreesanth,Munaf.We need to have good bowling against world class Australia if we have to win the match.In battin dept. we should have a good start as we are playing with 5 bowlers.I wish & pray for sachin's century & when Sachin Plays Vs Australia , He is in teriffic form.We have to do our best to win this match......................................
.......................Best luck Indian Cricketers............Sachin,Viru,Yuvi,Zaheer,Bhaji........

Happy Holi

Holi (होली), is a spring religious festival celebrated by Hindus. It is primarily observed in India, Nepal, Sri Lanka, and countries with large Indic diaspora populations, such as Suriname, Malaysia, Guyana, South Africa, Trinidad, United Kingdom, United States, Mauritius, and Fiji. In West Bengal and Orissa of India it is known as Dolyatra (Doul Jatra) (Bengali: দোলযাত্রা), or Basanta-Utsav ("spring festival")(Bengali: বসন্তোৎসব), . The most celebrated Holi is that of the Braj region, in locations connected to the Lord Krishna: Mathura, Vrindavan, Nandagaon, and Barsana. These places have become tourist destinations during the festive season of Holi, which lasts here to up to sixteen days.

The main day, Holi, also known as Dhuli Vandana in Sanskrit, also Dhulheti, Dhulandi or Dhulendi, is celebrated by people throwing coloured powder and coloured water at each other. Bonfires are lit the on the eve of the festival, also known as Holika Dahan (burning of Holika) or Chhoti Holi (little Holi). The bonfires are lit in memory of the miraculous escape that young Prahlad accomplished when Demoness Holika, sister of Hiranyakashipu, carried him into the fire. Holika was burnt but Prahlad, a staunch devotee of god Vishnu, escaped without any injuries due to his unshakable devotion. Holika Dahan is referred to as Kama Dahanam in South India.

Holi is celebrated at the end of the winter season on the last full moon day of the lunar month Phalguna (February/March), (Phalgun Purnima), which usually falls in the later part of February or March. In 2009, Holi (Dhulandi) was on March 11 and Holika Dahan was on March 10. In 2010, Holi was on March 1 and Holika Dahan was on February 28.

In 2011, Holi was on March 20 and Holika Dahan was on March 19.

Rangapanchami occurs a few days later on a Panchami (fifth day of the full moon), marking the end of festivities involving colours.

Wednesday, March 16, 2011

SAVE TIGER ,SAVE ANIMAL

BABA AMTE,SOCIAL WORKER

Murlidhar Devidas Amte, popularly known as Baba Amte (Marathi: बाबा आमटे) (December 26, 1914 – February 9, 2008) was an Indian social worker and social activist known particularly for his work for the rehabilitation and empowerment of poor people suffering from leprosy.
Trained in law, Amte developed a successful legal practice at Wardha. He soon got involved in the Indian struggle for freedom from the British Raj, and started acting as a defense lawyer for leaders of the Indian freedom movement whom the British authorities had imprisoned in the 1942 Quit India movement. He spent some time at Sevagram ashram of Mahatma Gandhi, and became a follower of Gandhism for the rest of his life. He practiced various aspects of Gandhism, including yarn spinning using a charkha and wearing khadi.

Amte founded three ashrams for treatment and rehabilitation of leprosy patients, disabled people, and people from marginalized sections of the society in Maharashtra, India.

In 1973, Amte founded the Lok Biradari Prakalp to work among the Madia Gond tribal people of Gadchiroli District.

Amte devoted his life to many other social causes, the most notable among which were generating public awareness of importance of ecological balance, wildlife preservation, and the Narmada Bachao Andolan.
Amte followed Gandhi's way of living, and led a spartan life. He wore khadi clothes made from the looms at Anandwan. He believed in Gandhi's concept of a self-sufficient village industry that empowers seemingly helpless people, and successfully brought his ideas into practice at Anandwan.

Amte also used Gandhian principles to fight against corruption, mismanagement, and poor, shortsighted planning in the government. Thus, he used non-violent means to fight the Indian government in the fight of independence [11].

In spite of his emulation of social and political work, unlike Gandhi, Amte was an atheist

STEVE JOBS

Steven Paul Jobs (born February 24, 1955) is an American business magnate and inventor. He is the co-founder and chief executive officer of Apple Inc. Jobs also previously served as chief executive of Pixar Animation Studios; he became a member of the board of The Walt Disney Company in 2006, following the acquisition of Pixar by Disney. He was credited in the 1995 movie Toy Story as an executive producer.

In the late 1970s, Jobs, with Apple co-founder Steve Wozniak, Mike Markkula, and others, designed, developed, and marketed one of the first commercially successful lines of personal computers, the Apple II series. In the early 1980s, Jobs was among the first to see the commercial potential of the mouse-driven graphical user interface which led to the creation of the Macintosh.After losing a power struggle with the board of directors in 1984, Jobs resigned from Apple and founded NeXT, a computer platform development company specializing in the higher education and business markets. Apple's subsequent 1996 buyout of NeXT brought Jobs back to the company he co-founded, and he has served as its CEO since 1997.

In 1986, he acquired the computer graphics division of Lucasfilm Ltd which was spun off as Pixar Animation Studios. He remained CEO and majority shareholder at 50.1% until its acquisition by The Walt Disney company in 2006.Consequently Jobs became Disney's largest individual shareholder at 7% and a member of Disney's Board of Directors

My Quote-