Thursday, July 30, 2009

In C, Fales is represented by an expression with a value of 0. choose the valid expression that can be used to

represent False a: the null pointer B:a floating expression haveing the value 0.0 C: the null character '\0' D: all of the above.

In C, Fales is represented by an expression with a value of 0. choose the valid expression that can be used to
Sure - let's take 'em all. The answer is D.





(C WILL TREAT NULLS AS FALSE. Period. Perhaps someone is thinking of SQL and other languages where NULL != 0, but that's NOT the case in C.)





Null pointers are often returned from functions indicating failure. Thus, null pointers can be tested as false.





Null character '\0' ( 00 000 000) itself is zero and will equate to false.





Value of 0, whether 0.0 as a double or float, int, short, long, etc, is still zero and will equate to false.





Have a look with this program:


#include %26lt;stdio.h%26gt;





int main() {





char myChar='\0';


double myDouble=0.0;


char * myPtr = NULL;





if ( ! myChar )


printf ("NOT MyChar - FALSE\n");


else


printf ("myChar - TRUE\n");





if ( ! myDouble )


printf ("NOT myDouble - FALSE\n");


else


printf ("myDouble - TRUE\n");





if ( ! myPtr )


printf ("NOT myPtr - FALSE\n");


else


printf ("myPtr - TRUE\n");


}


"testit.c" 27 lines, 367 characters


reznet1__/disc12/users/resnimi-%26gt; make testit


cc -O testit.c -o testit


reznet1__/disc12/users/resnimi-%26gt; ./testit


NOT MyChar - FALSE


NOT myDouble - FALSE


NOT myPtr - FALSE
Reply:its B. the null value refers to empty meaning no value at all so it cannot be equal to zero. and the only B can be used to represent false is if you typecast it to int since int and float have different memory allocations
Reply:B. All of the other answers include NULL. Null doesn't have a value. Null != 0. Always remember that. Even a floating expression with a value of 0 will be 0. NULLS are not 0.


Write a C program?

Write a C function addr() that has three arguments, the first is a pointer to a two dimensional dynamic array, the second is an integer that describes the number of its rows, the third argument is an integer that describe its number of columns.


Function addr() adds one new row (as the last one) to the dynamic array using realloc(). It returns the pointer to the new (possibly reallocated) array.





int **addr(int **p,int rows,int columns);

Write a C program?
I don't see a point in returning the pointer to the array that is already pointed to by p. You could return success or failure which could help the caller in knowing whether the array was really realloc'd.





homework? ;)


read man realloc on a Unix/Linux machine


Write a program to demonstrate huge pointer and far pointer? Also describe what is TSR program in C?

Now?

Write a program to demonstrate huge pointer and far pointer? Also describe what is TSR program in C?
Look for book "Writing TSR in C" book by Indian Author Yashwant Kanetkar. It should have both the answers for you.





you can buy it form following link


C programming - Consider an int variable x and consider a pointer float* p=(float*)&x pointing to x.?

Consider an int variable x and consider a pointer float* p=(float*)%26amp;x pointing to x. If we store a float value 2.35 in x directly using x = 2.35 or indirectly using *p=2.35, will we get the same bit pattern stored in x in both cases or instead different patterns? Explain your answer, just “Yes” or “No” is not sufficient.

C programming - Consider an int variable x and consider a pointer float* p=(float*)%26amp;x pointing to x.?
The bit pattern for x = 2.35 is not the same as *p = 2.35.





This is because you defined x as a int and when you assign 2.35 (a float) to x (an integer) the C language will automatically cast the value of 2.35 to an int. So x will be assigned the value of 2.





However, since you defined p as a pointer to a float and since x is 4 bytes and a float is 4 bytes, you can actually use a pointer to a float to put a floating point value in an integer variable. Just don't expect to be able to look at the variable x and get anything meaningful.
Reply:first of all float pointer can't hold address of integer variable so its no question about storing value any way

imperial

Any pointers or tips?

I'm relatively new to cooking, and tonight I'm trying my hardest to surprise my husband with his favorite dish, Steak stuffed Creamy Spinach. However, this is my first attempt and I "suck" at baking with timing and tempertures. I don't even have fine cook ware to help me. This will all be done by appx time. Any pointer or tips for this recipe (listed below):





SPINACH - STUFFED FLANK STEAK





2 (1 lb.) beef flank steaks


1 beaten egg


1 (10 oz.) pkg. frozen chopped spinach, cooked %26amp; drained


1/2 c. shredded sharp American cheese (2 oz.)


1/2 tsp. ground sage


1/4 tsp. salt


Dash pepper


3/4 c. soft bread crumbs


2 tbsp. cooking oil


1 (8 oz.) can tomato sauce


1/2 c. dry red wine


1/2 c. chopped onion


1 clove garlic, minced


2 tbsp. all-purpose flour





Pound each steak with meat mallet to 1/4 inch thickness; set aside. Combine egg, spinach, cheese, sage, salt and pepper. Stir in soft bread crumbs. Spread spinach filling over steaks. Starting from narrow side, roll up each steak li

Any pointers or tips?
Ok, I should have looked longer before I asked about the recipe! It looks really good!


After you drain the spinach, be sure to "pat it dry" - spinach retains a LOT of water and you need to get as much of the water out as possible. It doesn't say what temperature to cook it at, but it's usually around 350-375 degrees.


Have fun with it! He'll be glad you tried so hard!
Reply:Just combine tomato sauce, wine, onion and garlic; pour over meat. Cover with foil; bake at 350 degrees until tender, about 1 1/2 hours.





Transfer meat to serving platter; keep warm. Pour pan juice into measuring cup; add water to equal 1 3/4 cups. Pour juice mixture into a 1 quart saucepan. Combine 1/4 cup cold water and flour; stir into pan juices. Cook and stir over medium heat until thickened and bubbly.
Reply:Honey, the recipe looks great. You can do this, and he'll be so proud of you.


In C Function - before initializing a char variable, the char contains same junk - why?

With in a C program, I have a local C Function. In this function, I define a local char pointer. Before initializing the char, the char contains same junk value, even if I run millions of times - why?





How come the memory space contains the same junk char value - always?

In C Function - before initializing a char variable, the char contains same junk - why?
I'll give you the general answer. It'll be uninitialized because nothing initialized it to begin with. If it appears to be uninitialized every time you run, it could be the physical address is changing on each run. Now in your case, it sounds like you're looking at the same physical address each time, overwriting it, and re-running to see the data you overwrote. Either the overwrite failed, or between runs perhaps something else used the space. Your debugger can verify the overwrite if you dump the address space contents before leaving your program. As far as what uses that space after, there are software tools that let you watch writes to an address, but as you can imagine they're very intrusive and may end up changing the behavior you're seeing.
Reply:That's the way C language operates. Before initialization, your variable contains unexpected data.





This is a source of many bugs actually. Other programming languages might prohibit you from using unassigned variables (such as C Sharp)





Hope this helps.
Reply:Ok, as you know a local variable's value is stored on the stack--and you're asking why the uninitialized value of a local character variable doesn't return random data. The simple fact is that you are initializing values on the stack and then re-using them when you call the the function and examine the value of the local variable. As suggested in another answer, you can prove all this to yourself using a debugger. I like gdb that comes with gnu-c. Examine your stack and addresses that your local variables point to, etc. The debugger is an excellent way for you learn C and all of its nuances.


Good Luck


Visual C++ Experts helppppp!!!!?

I made a small program (for fun). One of my main objectives here is that when mouse pointer is not moving for 5 seconds, the mouse pointer will disappear and reappear again if mouse is moved by the user...





How to determine / check if mouse pointer is moving or not?


(please do not write the entire code for this... I only want the piece of code that is responsible for analyzing the movement of the mouse... and for the rest, I know how to handle it...)





I use ShowCursor to hide my mouse pointer...





--- MFC or not, as long as it is Visual C++ code, is accepted.





I promise to give credits if and only if I am satisfied with the answer....


Thanks and God Bless...

Visual C++ Experts helppppp!!!!?
Bravo for not wanting to see the code....you are one of the rare kids that request this that is for sure...anyway, i will grant your wish and have you recall this VC win32 api:





GetCursorPos(...);





So you have a number of choices but here is one of them to solve your problem:





You'd want to store the current position of the cursor which is done after 5 secs of it not moving ...obviously in your code you are using a timer and if the cursor position hasn't moved for 5 secs it turns off the cursor via ShowCursor....it is then that you store the position of the cursor....





Now for the cursor movement events that come in (recal that windows triggers events for when the mouse moves) you can then verify the x/y position vs what you stored...and if it changed then you can display the mouse cursor again and start your original 5sec timer (assuming it was disabled when it blanked it -- to be efficient).





Btw, you prolly already are doing this, but as a friendly reminder you can always create your own timer event that windows will keep track of and initiate the WM_TIMER message on your behalf every xx secs (in this case: 5 secs) for you...this would be the most eifficient way for a timer to be made in your code since it will be using less resources.