C Programming Basic Concepts

What is C language?

The C programming language is a standardized programming language developed in the early 1970s by Ken Thompson and Dennis Ritchie for use on the UNIX operating system.

What are the two types of Constants in C?

  1. Primary Constants.
  2. Secondary Constants.

What is the difference between “printf(…)” and “sprintf(…)”?

sprintf(…) writes data to the character array whereas printf(…) writes data to the standard output device.

How to reduce a final size of executable?

Size of the final executable can be reduced using dynamic linking for libraries.

What is hashing?

To hash means to grind up, and that’s essentially what hashing is all about. The heart of a hashing algorithm is a hash function that takes your nice, neat data and grinds it into some random-looking integer.

Are you Looking for C Programming Online Training? Please Enroll for Demo C Programming..!

What are the different storage classes in C?

C has three types of storage: automatic, static and allocated.  Variable having block scope and without static specifier have automatic storage duration.

What are the differences between malloc() and calloc()?

There are 2 differences.

First, is in the number of arguments. malloc() takes a single argument(memory required in bytes), while calloc() needs 2 arguments(number of variables to allocate memory, size in bytes of a single variable).

Secondly, malloc() does not initialize the memory allocated, while calloc() initializes the allocated memory to ZERO.

What is the difference between const char* p and char const* p?

In const char* p, the character pointed by ‘p’ is constant, so u cant change the value of character pointed by p but u can make ‘p’ refer to some other location.

In char const* p, the ptr ‘p’ is constant not the character referenced by it, so u cant make ‘p’ to reference to any other location but u can change the value of the char pointed by ‘p’.

How can you determine the size of an allocated portion of memory?

You can’t, really. free() can , but there’s no way for your program to know the trick free() uses. Even if you disassemble the library and discover the trick, there’s no guarantee the trick won’t change with the next release of the compiler.

Can static variables be declared in a header file?

You can’t declare a static variable without defining it as well (this is because the storage class modifiers static and extern are mutually exclusive). A static variable can be defined in a header file, but this would cause each source file that included the header file to have its own private copy of the variable, which is probably not what was intended.

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.

What is the output of printf(“%d”) ?

When we write printf(“%d”, x); this means compiler will print the value of x. But as here, there is nothing after %d so compiler will show in output window garbage value.

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 pointer

How to reduce a final size of executable?

Size of the final executable can be reduced using dynamic linking for libraries.

How are pointer variables initialized?

Pointer variable are initialized by one of the following two ways

  1. Static memory allocation
  2. Dynamic memory allocation
Are you Looking for C Programming Training? Please Enroll for Demo C Programming..!

What is a method?

Method is a way of doing something, especially a systematic way; implies an orderly logical arrangement (usually in steps).

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.