C QUESTIONS How Do You Decide Which Integer Type To
C QUESTIONS How Do You Decide Which Integer Type To
What should the 64-bit type on a machine that can support it?
typedef struct {
char *item;
NODEPTR next;
} *NODEPTR;
int f()
{
char a[] = "Hello, world!";
}
char *p = malloc(10);
struct x1 { ... };
typedef struct { ... } x2;
Why doesn't
struct x { ... };
x thestruct;
work?
struct name {
int namelen;
char namestr[1];
};
and then did some tricky allocation to make the namestr array
act like it had several elements. Is this legal or portable?
struct list {
char *item;
struct list *next;
}
main(argc, argv)
{ ... }
work?
int i = 3;
i = i++;
If I'm not using the value of the expression, should I use i++
or ++i to increment a variable?
work?
I'm trying to declare a pointer and allocate some space for it,
but it's not working. What's wrong with this code?
char *p;
*p = malloc(10);
((int *)p)++;
work?
int *ip;
f(ip);
I have a function
f(&5);
If NULL and 0 are equivalent as null pointer constants, which should I use?
What does a run-time "null pointer assignment" error mean? How can I track it down?
Why are array and pointer declarations interchangeable as function formal parameters?
How can I set an array's size at run time? How can I avoid fixed-sized arrays?
How do I write functions which accept two-dimensional arrays when the width is not known at compile time?
How can I use statically- and dynamically-allocated multidimensional arrays interchangeably when passing them
to functions?
Why doesn't sizeof properly report the size of an array when the array is a parameter to a function?
char *answer;
printf("Type something:\n");
gets(answer);
printf("You typed \"%s\"\n", answer);
char *p;
strcpy(p, "abc");
Why am I getting "warning: assignment of pointer from integer lacks a cast" for calls to malloc()?
Why does some code carefully cast the values returned by malloc to the pointer type being allocated?
Why isn't a pointer null after calling free()? How unsafe is it to use (assign, compare) a pointer value after it's
been freed?
When I call malloc() to allocate memory for a pointer which is local to a function, do I have to explicitly free() it?
I'm allocating structures which contain pointers to other dynamically-allocated objects. When I free a structure,
do I also have to free each subsidiary pointer?
Can I query the malloc package to find out how big an allocated block is?
What's the difference between calloc() and malloc()? Is it safe to take advantage of calloc's zero-filling? Does
free() work on memory allocated with calloc(), or do you need a cfree()?
Why doesn't
strcat(string, '!');
work?
How can I get the numeric (character set) value corresponding to a character, or vice versa?
Can I use an #ifdef in a #define line, to define something two different ways?
How can I use a preprocessor #if expression to tell if a machine is big-endian or little-endian?
What's the difference between "const char *p" and "char * const p"?
Why can't I pass a char ** to a function which expects a const char **?
What does the message "warning: macro replacement within a string literal" mean?
char c;
while((c = getchar()) != EOF) ...
while(!feof(infp)) {
fgets(buf, MAXLINE, infp);
fputs(buf, outfp);
}
What printf format should I use for a typedef like size_t when I don't know whether it's long or some other type?
How can I print numbers with commas separating the thousands? What about currency formatted numbers?
double d;
scanf("%f", &d);
work?
How can I tell how much destination buffer space I'll need for an arbitrary sprintf call? How can I avoid
overflowing the destination buffer with sprintf()?
How can I convert numbers to strings (the opposite of atoi)? Is there an itoa() function?
Why does strncpy() not always place a '\0' terminator in the destination string?
How can I split up a string into whitespace-separated fields? How can I duplicate the process by which main() is
handed argc and argv?
How can I add N days to a date? How can I find the difference between two dates?
What does it mean when the linker says that _end is undefined?
When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?
How can %f be used for both float and double arguments in printf()? Aren't they different types?
How can I write a function that takes a format string and a variable number of arguments, like printf(), and
passes them to printf() to do most of the work?
How can I write a function analogous to scanf(), that calls scanf() to do most of the work?
How can I discover how many arguments a function was actually called with?
How can I write a function which takes a variable number of arguments and passes them to some other function
(which takes a variable number of arguments)?
How can I call a function with an argument list built up at run time?
C QUESTIONS
C++ QUESTIONS
What is a class?
What is an object?
What is the difference between an object and a class?
What is the difference between class and structure?
What is public, protected, private?
What are virtual functions?
What is friend function?
What is a scope resolution operator?
What do you mean by inheritance?
What is abstraction?
What is polymorphism? Explain with an example.
What is encapsulation?
What do you mean by binding of data and functions?
What is function overloading and operator overloading?
What is virtual class and friend class?
What do you mean by inline function?
What do you mean by public, private, protected and friendly?
When is an object created and what is its lifetime?
What do you mean by multiple inheritance and multilevel inheritance? Differentiate
between them.
Difference between realloc() and free?
What is a template?
What are the main differences between procedure oriented languages and object oriented
languages?
What is R T T I ?
What are generic functions and generic classes?
What is namespace?
What is the difference between pass by reference and pass by value?
Why do we use virtual functions?
What do you mean by pure virtual functions?
What are virtual classes?
Does c++ support multilevel and multiple inheritance?
What are the advantages of inheritance?
When is a memory allocated to a class?
What is the difference between declaration and definition?
What is virtual constructors/destructors?
In c++ there is only virtual destructors, no constructors. Why?
What is late bound function call and early bound function call? Differentiate.
How is exception handling carried out in c++?
When will a constructor executed?
What is Dynamic Polymorphism?
Write a macro for swapping integers.