C Funda
C Funda
A goto statement implements a local jump of program execution, and the longjmp() and setjmp() functions implement a nonlocal, or far, jump of program execution. Generally, a jump in execution of any kind Latest Answer : using the normal goto statement we can move only within the function. it is not possible to go from one function to another function.using setjmp and longjmp you can move from one function to another function. but it is very bad programming. since the ...
What is an lvalue? An lvalue is an expression to which a value can be assigned. The lvalue expression is located on the left side of an assignment statement, whereas an rvalue is located on the right side of an assignment Latest Answer : lvalue is is a memory location,whose value is not constant i.e it's value is changed when a new value entered into that location.And also it can be say as, it is an expression,where left side we have an identifier and right side(rvalue) the ...
What is page thrashing? Some operating systems (such as UNIX or Windows in enhanced mode) use virtual memory. Virtual memory is a technique for making a machine behave as if it had more memory than it really has, by using disk Latest Answer : First of all there is a one sentence definition of Page Thrashing (I believe someone posted a similar answer here):Page Thrashing only comes about when you use Virtual Memory which requires an MMU and "fools" a process into believing that it ...
When should the register modifier be used? Does it really help? The register modifier hints to the compiler that the variable will be heavily used and should be kept in the CPU s registers, if possible, so that it can be accessed faster. There are several restrictions Latest Answer : If a variable is defined by using register modifier it tells to the compiler that the variable is used repetedly and that variable executes fastly. Generally register variables are defined in loop counters. This variable stored in CPU registers and access ...
When should the volatile modifier be used? The volatile modifier is a directive to the compiler s optimizer that operations involving this variable should not be optimized in certain ways. There are two special cases in which use of the
What is the benefit of using const for declaring constants? The benefit of using the const keyword is that the compiler might be able to make optimizations based on the knowledge that the value of the variable will not change. In addition, the compiler will try Latest Answer : A side effect benefit:Say you want to pass an argument that you do not want modified, but you do not want to pass by value.Solution pass as constant reference or pointer constant.int someFoo(myDataType const &chunkOfData);orint ...
What is the quickest sorting method to use? The answer depends on what you mean by quickest. For most sorting problems, it just doesn t matter how quick the sort is because it is done infrequently or other operations take significantly more Latest Answer : The algorithms which follows divide and qunquer technique provides fastest implementation. ...
How can I sort things that are too large to bring into memory? A sorting program that sorts items that are on secondary storage (disk or tape) rather than primary storage (memory) is called an external sort. Exactly how to sort large data depends on what is meant Latest Answer : Any how after merging that it will create the same problem to sort out. Will you please explain about that? ...
What is the benefit of using #define to declare a constant? Using the #define method of declaring a constant enables you to declare a constant in one place and use it throughout your program. This helps make your programs more maintainable, because you need to Latest Answer : When you define constant variable there is possiblity that it's value may get changed in the program accidently by use of say pointer, but if you define constant by #define it's value can't be changed. This is also one of the benifit ...
What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used? The strcpy() function is designed to work exclusively with strings. It copies each byte of the source string to the destination string and stops when the terminating null character () has been moved.
What is page thrashing? Some operating systems (such as UNIX or Windows in enhanced mode) use virtual memory. Virtual memory is a technique for making a machine behave as if it had more memory than it really has, by using disk Latest Answer : First of all there is a one sentence definition of Page Thrashing (I believe someone posted a similar answer here):Page Thrashing only comes about when you use Virtual Memory which requires an MMU and "fools" a process into believing that it ...
What is a const pointer? Latest Answer : a const pointer means the pointer which represents the address of one value. so if you declare a pointer inside the function, it doesn't have scope outside the function. if it is also available to the outside function whenever we declare a pointer as ...
When should the volatile modifier be used? The volatile modifier is a directive to the compiler s optimizer that operations involving this variable should not be optimized in certain ways. There are two special cases in which use of the
Can a variable be both const and volatile? Yes. The const modifier means that this code cannot change the value of the variable, but that does not mean that the value cannot be changed by means outside this code. For instance, in the example in Latest Answer : But isnt like the constant variables will be stored by in ROM (read only memory).Then how can the some process other than the code can change the value of const volatile ...
When should a type cast be used? There are two situations in which to use a type cast. The first use is to change the type of an operand to an arithmetic operation so that the operation will be performed properly. The second case Latest Answer : Type cast should be used in case of if we want to assign a void pointer to a pointer of some data type.eg:void *ptr;int *c;c=(int *)ptr; ...
When should a type cast not be used? A type cast should not be used to override a const or volatile declaration. Overriding these type modifiers can cause the program to fail to run correctly. A type cast should not be used to turn a pointer Latest Answer : we should not cast the big datatype to smaller one. Like from double to float long to integer. TIn these cases there will be chance of loosing the valuable data itself. ... Read Answers (1)
Answer Question
Subscribe
How do you redirect a standard stream? Most operating systems, including DOS, provide a means to redirect program input and output to and from different devices. This means that rather than your program output (stdout) going to the screen; Latest Answer : By using the operators "" we can redirect the standard input and out streams.example : d:> jinto.exe > outputredirected d:> ... Read Answers (2)
Answer Question
Subscribe
How can I open a file so that other programs can update it at the same time? Your C compiler library contains a low-level file function called sopen() that can be used to open a file in shared mode. Beginning with DOS 3.0, files could be opened in shared mode by loading a special View Question
Answer Question
Subscribe
What is indirection? If you declare a variable, its name is a direct reference to its value. If you have a pointer to a variable, or any other object in memory, you have an indirect reference to its value. View Question
Answer Question
Subscribe
What is a null pointer? There are times when it s necessary to have a pointer that doesn t point to anything. The macro NULL, defined in , has a value that s guaranteed to be different from any valid Latest Answer : hi, Null pointer: When referring to computer memory, a null pointer is a command used to direct a software program or operating system to an empty location in the computer memory. Commonly, the null pointer is used to denote the ...
Difference between reference and pointer? In C there is no concept of a reference variable. Only pointers exist. When you pass address of any variable to a function it is termed as pass by reference. Coz the formal parameter in function is the pointer that stores this address.
In C++ reference variables exist. A reference variable does not get any memory of its own. It must be initailzed when it is declared and it acts as an alias or synonym for the variable which was used to initialze it.
2) someFunction (a b);
In this case no memory is allocated to x & y. They act as alias for the memory locations to which a & b are referring. any changes made to the values of x & y will cause values of a & b in the calling function to change respectively.
Both approaches 1) and 2) are called pass by reference. But first approach uses pointers and second approach uses reference variables.
Overall Rating: +1
#2
RE: Difference between reference and pointer? Reference is any variable address represent '&' with front. But pointer is a variable. Which reference another variable. Reference variable holds value. Which is not a address.
C++ supports passing an object by reference and pointer former is widely used in the C++ where as C doesnot support passing user defined data by reference.
Pointer may point to variable or not at any given point in time. We can define pointer without having any data in hand. later we can make it to point to some data of defined type.
Reference can't be defined as pointer. to define reference we need to have data already available failing to do so generates compiler errror.
Above statments can be made working as Employee &ref manger; // manager is already created object.
Sum of two numbers without using arithmetic operators ex: int a=10; int b=10; int sum=a+b; without using "+" operator calculate sum void main() { int a=10,b=20; while(b--) a++; printf("Sum is :%d",a); }
printf() and printf as a variable can printf be used as a variable as well as a procedure? printf can be used as a variable . But once we declare a variable printf ,
standard Library function "printf" can not be recongnized by the compiler within the scope of the variable (reason :local symbol might be having higher precedence ). If at all library func is used ,compiler wil throw the error saying- " called object is not a function."
{ int printf; printf = 10; /* printf("n My Number = %d",num);*/ /* Activating this line,causes an error */ Display( printf); return 1; }
-Jayalakshmi Kaja
Above answer was rated as good by the following members: kmcanil, sourabh_t, rajani_vaddepalli15
p++ is a unary operator that is why it is fast as it operates on only one operand on the other hand p+1 + is a binary operator that is why it is slower as compared to ++
What's the "condition" so that the following code prints both HelloWorld !
if "condition"
if you want World!Hello then change 0 : 1 to 1 : 0 or void main(){ if ( ! ( printf("Hello ") ) ) printf("Hello"); else printf("World"); }
Identify the correct argument for the function call fflush() in ANSI C: A)stdout B)stdin C)stderr D)All the above fflush()'s purpose is to write any buffered output data for the specified stream.fflush is used on the standard output stream because stdout is usually buffered and the output might not be prompted immediately.
compiler time error- the errors that compiler identifies like syntax error, type mismatch/ type casting errors. Runtime error- those errors that occur while executing a program like semantic errors, for eg, logical errors, stack overflow- , segmentation fault.
main() { printf("%d",(2.5*2.5)); }
above gives output of 0 plss explain by default the real number constants (i.e. 2.5 3.14 etc) are considered as double. Double is stored using IEEE floating point standard. the (2.5 *2.5) gives double. when this double is passed to the printf and printed using %d. function assumes that argument is integer. So there is Data loss of 6 bytes. and U can think what will be effect of loosing 6 bytes.
Develop a program that receives the month and year from the keyboard as integers and prints the calendar in the following format March 2006 Mon Tue Wed Thu Fri Sat Sun 12345 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Note that according to gregorian calendar 01/01/1900 was monday.With this as the base the calendar should be generated.
#include<stdio.h> #include<conio.h> //0 is for monday 1 for tuesday and so on int leapyear(int year)
{ if (year 400 0) return 1; if (year 4 0 && year 100 ! 0) return 1; return 0; } int year_days[] {0 31 28 31 30 31 30 31 31 30 31 30 31}; void main() { int days no_of_leap yeardif month year oddays i; month 1; clrscr(); printf ("nEnter the month and the year: "); scanf (" d d" &month &year); yeardif year - 1900; no_of_leap yeardif / 4; if (leapyear(year)) no_of_leap--; oddays no_of_leap * 2; oddays + (yeardif - no_of_leap); for (i 1;i<month;i++) { oddays + year_days[i]; }
if (leapyear(year) && month >2) oddays++; oddays oddays 7; printf ("ntMontTuetWedt Thut Frit Satt Sunn"); for (i 0;i<oddays;i++) printf (" "); if (leapyear(year) && month 2) days 29; else days year_days[month]; for (i 1;i< days;i++) { if ((i+oddays) 7 1) printf ("n"); printf (" 9d" i); } getch(); }
Pseudo is not a programming language. It is your language. before writtinga program we usually draw a blue print on the papar. like
if a > 0 then show a proper message else get the data from user.
like and then we write this in C++ or Java or any language which you know.
why scanf("%d",&n) and gets(string) don't work tog... This is a general problem of the keyboard buffer. When scanf(" d" &n); is used and when an input is entered the newline character("n") along with the input is stored in buffer. This buffer gets clear as the user presses "Enter" or if the buffer is full.
So when we use the scanf(" d" &n); the "n" is left in the buffer itself. So the buffer will fill the string with " ". Hence it will not print anything in place of string.
printf("Number :: d" n); printf("String :: s" string); if(strcmp(string " ") 0) printf("Null string"); system("pause"); return 0; }
Here initially i am trying to print the contents of the string.... It gives garbage.Later in the output Null string will be displayed. Which means the string is containing " ".
Note : When we change the order ie. gets(string); and then scanf( d" &n); we will not have this problem.
Solution : The solution for such problems is to use fflush(stdin); This clears the keyboard buffer. Hence we can get the desired output. This fflush() should be used after entering the input. ie after scanf() and before gets().
printf("String :: s" string); printf("Enter the number"); scanf(" d" &n); fflush(stdin); printf("nEnter the string"); gets(string);
printf("Number :: d" n); printf("String :: s" string); if(strcmp(string " ") 0) printf("Null string"); system("pause"); return 0; }
can we include a header file in another header fil... Ya. You can include header file in another file.
//In test.c
Why is that a pointer is depicted by '*' in C? pointer is depicted by '*' . this is to differentiate a pointervariable from normal variable. it will tell the compiler that it is not a normal variable but it is a pointer variable which is holding the address of another variable. so use of '*' is only to differentiate a pointer variable from normal variable. i hope it is clear for you know.
Write any small program that will compile in "C" b... The following program compiles with 'C' with a warning about return type of main. But it wouldn't compile with 'C++' it gives error there: void main() { return; }