81. How can we read/write Structures from/to data files?
Ans: To write out a structure we can use fwrite() as Fwrite( &e, sizeof(e),1,fp);Where e is a structure variable. A corresponding fread() invocation can read the structure back from file. calling fwrite() it writes out sizeof(e) bytes from the address &e. Data files written as memory images with fwrite(),however ,will not be portable, particularly if they contain floating point fields or Pointers. This is because memory layout of structures is machine and compiler dependent. Therefore, structures written as memory images cannot necessarily be read back by programs running on other machine, and this is the important concern if the data files you’re writing will ever be interchanged between machines.
Ans: To write out a structure we can use fwrite() as Fwrite( &e, sizeof(e),1,fp);Where e is a structure variable. A corresponding fread() invocation can read the structure back from file. calling fwrite() it writes out sizeof(e) bytes from the address &e. Data files written as memory images with fwrite(),however ,will not be portable, particularly if they contain floating point fields or Pointers. This is because memory layout of structures is machine and compiler dependent. Therefore, structures written as memory images cannot necessarily be read back by programs running on other machine, and this is the important concern if the data files you’re writing will ever be interchanged between machines.
Advertisement
82. Write a program which employs Recursion?
Ans: int fact(int n) { return n > 1 ? n * fact(n – 1) : 1; }
83. Difference between array and pointer?
Ans:
Array
1- Array allocates space automatically
2- It cannot be resized
3- It cannot be reassigned
4- sizeof (arrayname) gives the number of bytes occupied by the array.
Pointer
1-Explicitly assigned to point to an allocated space.
2-It can be sized using realloc()
3-pointer can be reassigned.
4-sizeof (p) returns the number of bytes used to store the pointer variable p.
84. What are C identifiers?
Ans: These are names given to various programming element such as variables, function, arrays.It is a combination of letter, digit and underscore.It should begin with letter. Backspace is not allowed.
85. Write a program to interchange 2 variables without using the third one.
Ans:
a ^= b; ie a=a^b
b ^= a; ie b=b^a;
a ^= b ie a=a^b;
here the numbers are converted into binary and then xor operation is performed. You know, you’re just asking “have you seen this overly clever trick that’s not worth applying on modern architectures and only really applies to integer variables?”
Ans: int fact(int n) { return n > 1 ? n * fact(n – 1) : 1; }
83. Difference between array and pointer?
Ans:
Array
1- Array allocates space automatically
2- It cannot be resized
3- It cannot be reassigned
4- sizeof (arrayname) gives the number of bytes occupied by the array.
Pointer
1-Explicitly assigned to point to an allocated space.
2-It can be sized using realloc()
3-pointer can be reassigned.
4-sizeof (p) returns the number of bytes used to store the pointer variable p.
84. What are C identifiers?
Ans: These are names given to various programming element such as variables, function, arrays.It is a combination of letter, digit and underscore.It should begin with letter. Backspace is not allowed.
85. Write a program to interchange 2 variables without using the third one.
Ans:
a ^= b; ie a=a^b
b ^= a; ie b=b^a;
a ^= b ie a=a^b;
here the numbers are converted into binary and then xor operation is performed. You know, you’re just asking “have you seen this overly clever trick that’s not worth applying on modern architectures and only really applies to integer variables?”
Advertisement
86. What are the two forms of #include directive?
Ans:
1.#include”filename”
2.#include
the first form is used to search the directory that contains the source file.If the search fails in the home directory it searches the implementation defined locations.In the second form ,the preprocessor searches the file only in the implementation defined locations.
87. What do the functions atoi(), itoa() and gcvt() do?
Ans:
atoi() is a macro that converts integer to character.
itoa() It converts an integer to string
gcvt() It converts a floating point number to string
88. What is the difference between the functions memmove() and memcpy()?
Ans: The arguments of memmove() can overlap in memory. The arguments of memcpy() cannot.
89. What is a file?
Ans: A file is a region of storage in hard disks or in auxiliary storage devices.It contains bytes of
information .It is not a data type.
90. what is a stream? (IMP)
Ans: A stream is a source of data or destination of data that may be associated with a disk or other I/O device. The source stream provides data to a program and it is known as input stream. The destination stream Receives the output from the program and is known as output stream.
Ans:
1.#include”filename”
2.#include
the first form is used to search the directory that contains the source file.If the search fails in the home directory it searches the implementation defined locations.In the second form ,the preprocessor searches the file only in the implementation defined locations.
87. What do the functions atoi(), itoa() and gcvt() do?
Ans:
atoi() is a macro that converts integer to character.
itoa() It converts an integer to string
gcvt() It converts a floating point number to string
88. What is the difference between the functions memmove() and memcpy()?
Ans: The arguments of memmove() can overlap in memory. The arguments of memcpy() cannot.
89. What is a file?
Ans: A file is a region of storage in hard disks or in auxiliary storage devices.It contains bytes of
information .It is not a data type.
90. what is a stream? (IMP)
Ans: A stream is a source of data or destination of data that may be associated with a disk or other I/O device. The source stream provides data to a program and it is known as input stream. The destination stream Receives the output from the program and is known as output stream.