answersLogoWhite

0

📱

C Programming

Questions related to the C Computer Programming Language. This ranges all the way from K&R to the most recent ANSI incarnations. C has become one of the most popular languages today, and has been used to write all sorts of things for nearly all of the modern operating systems and applications. It it a good compromise between speed, power, and complexity.

9,649 Questions

Is the main function in C a built-in function or user-defined function?

The main function in C is user-defined. Built-in functions are simply those that do not require a library to be included, but every program must provide a user-defined point of entry; it cannot be built-in. Indeed, most functions in C are user-defined; the built-in functions are mostly operators rather than functions although most do behave like functions. The standard library functions are not built-in either; they all require the inclusion of the appropriate standard library header.

Write a c program to reverse string using static implementation of stack?

#include<stdio.h>

#include<conio.h>

#include<string.h>

int main()

{

char str[100];

int i,temp;

printf("Enter any string : ");

gets(str);

for(i=0; str[i]!=NULL; i++)

{

if(str[i+1]==' ' str[i+1]==NULL)

{

for(temp=i; temp>=0 && str[temp]!=' '; temp--)

printf("%c", str[temp]);

}

printf(" ");

}

getch();

return 0;

}

How do you find the nth number?

Basically the nth number is any possible number in the world!! Generally if you come across a question like this there will be more to it.

For example:

In the sequence 2, 4, 6, 8, 10.... what is the nth term?

This means that they want a general formula for each term. So if x is the term number, the nth term would be 2x.

That's all the information I can give you, I'm sure someone else might be able to help a little more :)

On dividing 2272 as well as 875 by 3 digit no N we get the same remainder The sum of the digits of N is?

Clearly, (2272 - 875) = 1397, is exactly divisible by N.

Now, 1397 = 11 x 127

The required 3-digit number is 127, the sum of whose digits is 10.

Calloc allocates a block of memory for an array of elements of a certain size?

No. The calloc function allocates a block of memory for a count of a specific type. The size of the type is already known to the compiler so does not need to be specified, it will automatically multiply the type's size by the count. With malloc, you have to allocate memory in bytes, therefore you need to calculate exactly how many bytes you will need for a given type and the number of elements of that type.

Examples (allocate 100 integers):

int* p = (int*) malloc (sizeof (int) * 100);

int* q = (int*) calloc (int, 100);

Note also that malloc does not initialise the memory whereas calloc does (the allocated memory is initialised with the value zero). As such, malloc is more efficient when you want to initialise the memory by copying from other memory. That is, there's no point initialising memory you're going to initialise manually, so long as you don't access that memory before it is initialised.

How can you declare global and local variable in pseudocode?

A local variable is a variable declared inside a construct, such as a class or function, while a global variable is a variable declared outside of any construct.

What is complier and its types in c?

C compiler is a set of program written in order to convert a user code into an executable code which is understood by a Computer.

What is static char in C?

static storage class in C tells that:

The variable will have the default value as zero.

The variable scope will be the file in which it is defined.

RaVi

How do you calculate address of any element of array using formulae?

element_address = array_address + (element_index * element_size)

Note that the array name refers to the start address of the array, element indices are always zero-based and element size is calculated at compile time using the sizeof() operator using the array type as the operand.

int x[10];

int* p1 = x + (5 * sizeof(int)); // calculate address of 6th element

int* p2 = &x[5]; // return address of 6th element

assert (p1==p2); // ensure both address are equal

Note that the array suffix operator [] used by p2 is merely sugar-coating. Behind the scenes, the compiler will automatically generate code equivalent to that of the p1 calculation. As such, there is no advantage in using one over the other.

Can two different pointer variables point to the same memory location?

Yes, two different pointer variables may point to the same memory location. Two issues, though... If your code thinks the two pointers represent two different allocations of memory, then you risk deallocating one and not realizing that the other is now invalid. You need to make sure that your compiler optimization settings for volatility are correct, otherwise the compiler could generate code that does not always work correctly.

What is the use of the default case in a switch case?

The default case in a switch statement will be activated if none of the other case values match. It is used exactly for this purpose - if nothing else matches in the switch then this one will always match.

Without a default case value, if nothing matched in the switch then nothing will be done. Sometimes it is necessary to know that nothing matched.

How can you insert a new node in a linked list before any given node within the linked list in O of 1?

you dont. you insert a node after it and copy all contents of the previous node in it and put the new values in the old node. just make sure to keep the connections intact.

How can you pass enum datatype as argument to function in c?

Here is the simple code, which demonstrates how you can use enum as function argument in c.

===================================================

#include <stdio.h>

// Enum declaration for power stat

enum PowerStat{ OFF, ON } powerStat; // Function printing the stat of power supply

void func( enum PowerStat ); int main(int argc, char* argv[])

{

// Set power supply stat OFF

powerStat = OFF;

// Call function to print the stat

func( powerStat);

// Set power supply stat ON

powerStat = ON;

// Call function to print the stat

func( powerStat);

return 0;

} void func( enum PowerStat stat)

{

printf("Power is = %s\n", stat ? "ON" : "OFF" );

} ==================================================

I haven't compiled and run above code but it has to work fine.

Let me know, if you found difficulty to compile it.

Email: ramji.jiyani@gmail.com

What is ADT how it is different from class?

ADT stands for abstract data type. It is basically a set of data values and associated operations that are specifically independent in nature. Examples of adt are stacks,trees,lists(doubly,circular,etc) and so on. Class is a user defined data type which the user can use in implementing a stack ADT or tree ADT. Class is used for implementation as it provides data hiding and encapsulation which are the features of ADT in object oriented programming. Hope this helps!