15 July, 2011

Case study: Lvalue error

Try the below programs and analyse the output.

A)
int main()
{
int n = 5;
int j;

j = ++n++;

printf("j = %d\n", j);
return 0;
}
o/p = ?

B)
int main()
{
int n = 5;
int *p = &n;
int j;

j = ++*p++;

printf("j = %d\n", j);
return 0;
}
o/p = ?

C)
int main()
{
int n = 5;
int *p = &n;
int j;

j = ++(*p)++;

printf("j = %d\n", j);
return 0;
}
o/p = ?

PS: First of all, U need to know operator precedence and associativity to understand the program.

14 July, 2011

String Palindrome - Recursive function

Hi all,

Write a program to find whether the given string is palindrome or not with the help of recursive functions.

NOTE: There are many ppl who are not active in this forum, i request them to wake up and reply to the questions posted or atleast to post some questions. Else those ppl will be removed from this forum.

07 July, 2011

Ternary Operator

main()
{
int a = 10, b = 7;
a >= 5 ? b = 100 : b = 200;
printf("B = %d\n",b);
}
When we compile this prg, I am getting an error like this:
3: error: lvalue required as left operand of assignment

What does this mean and how to resolve it?

13 June, 2011

Simple but not Simple!!!!!!

#include
main(){
int x=20;
printf("\n%d\t%d\t%d\n",x,x++,++x);
}

What is the o/p of the above prg and plz explain the logic???

02 June, 2011

Simple one!!!!!!

Whats the difference between "typedef"s and MACROs(#define)????

02 May, 2011

Const pointer Vs Pointer to a const

Does any one remember the difference between constant pointer and pointer to a constant.

I have three declaration:

const int *ptr;
int const *ptr;
int *const ptr;










28 April, 2011

Representing binary in C code

Hi all

    It has been a long time... :)

    Hey does any one know if it is possible to add prefix before a number to represent binary

    For example
        unsigned char a = 0xF0;    This is for hexadecimal
       
Is there a similar representation for binary and octal?
I already tried

    unsigned char a = 0b11110000;

It is possible in MPLAB but not with gcc on linux.
Any solutions...???



20 March, 2011

Useful tips in VIM Editore.

1. If you want to split the screen horizontally give command
:split
If you want to split the screen vertically give command
:vsplit
If you want to open an new/other exiting file in splited window give command
:new filename for horizontal window
:vnew filename for vertical window.
If you want to quit all window give command
:qall for quitting without saving the changes
:wqall for quitting with saving the changes
You can use normal quitting command for one particular splitted window like
q,wq
To move between the splitted window , use ctrl+ww

2. Folding techniques:
You can fold a block of code of a long file. The block can be anything like (),{},[]
or may be some code between the lines.
For example:
Suppose this is your code:
#include
.........................
.......
int main(void)
{
----
----
----
for(;;){

-----
-----
}
}

To fold the brackets {} of for loop, keep the cursor at opening bracket of the for loop and then use zfa} command. It will make a fold till the closing of the corresponding bracket. This technique also works form backward.
It means you can keep the cursor at the closing bracket and use command zfa{ .
For closing and opening the folds, move the cursor at the fold and use command za
If you want to fold the codes between particular lines , Use command
:beginning_line,closing_line fold
Give a space between closing line and fold command.You can also use fo instead of fold.

For more details about this folding option just visit the link.
http://www.linux.com/archive/feature/114138

17 March, 2011

Puzzle

You are given two ropes and a lighter. This is the only equipment you can use. You are told that each of the two ropes has the following property: if you light one end of the rope, it will take exactly one hour to burn all the way to the other end. But it doesn’t have to burn at a uniform rate. In other words, half the rope may burn in the first five minutes, and then the other half would take 55 minutes. The rate at which the two ropes burn is not necessarily the same, so the second rope will also take an hour to burn from one end to the other, but may do it at some varying rate, which is not necessarily the same as the one for the first rope. Now you are asked to measure a period of 45 minutes. How will you do it?

15 March, 2011

strdup() and strcpy()

whats the difference between strdup() and strcpy()? In which case, which of this is preferred????

08 March, 2011

#ifdef __cplusplus

#ifdef __cplusplus
extern "C" {
#endif

.............
............
. .
.
.
.
#ifdef __cplusplus
}
#endif

i have seen this piece of code in many files esp in header files... any idea what does this mean and when to use this????

06 March, 2011

difference between strcpy() and memcpy()???

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

28 February, 2011

Variable name conflicts

Is it possible to declare global and static variable with same name? if yes, static var will be stored in data segments, wont it get conflict?

eg:
#include

static int a = 0;

void func()
{
printf("a = %d\n", a);
}

int main(void)
{
static int a = 10;
printf("a = %d\n", a);
func();
return 0;
}

25 February, 2011

Zombie process

Does any one remember about zombie processes...
When a processes is stopped using Ctrl +Z is it called a zombie process? 
Read about it somewhere not sure if it is right.
Also check out these commands 
bg - Background
fg - Foreground