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

How memory is allocated for array type variable?

For any given type, T, a definition of type T[n] will allocate an array of n elements of type T in contiguous memory, for all n>=0. The total size of the allocation will be equivalent to n * sizeof(T). Elements of type T can be accessed by index, in the range 0 to n-1. These indices allow the compiler to compute the offset from the start of the array, such that index i refers to the address i * sizeof(T).

Arrays can be either fixed-size or variable-length and can be allocated on the stack or the heap but only fixed-size arrays can be allocated statically. The following shows all the possibilities:

int a[10]; // fixed-size, static allocation, global scope

void f(int n) {

int b[10]; // fixed-size, stack allocation, local scope

int c[n]; // variable-length, stack allocation, local scope

int* d = new int[10]; //fixed-size, heap allocation

int* e = new int[n]; // variable-length, heap allocation

// ...

delete [] e;

delete [] d;

}

Note that the arrays referred to by the pointers d and e are anonymous arrays (as are all heap allocations). It is important that we maintain at least one reference to a heap allocation in order to release that memory back to the system when we no longer require it. The pointers d and e will automatically fall from scope when the function ends, but the memory they refer to remains, unless we explicitly delete that memory. Ideally, the function that allocates heap memory should also release that memory, however so long as we maintain a reference to that memory (such as through a global pointer), any function can release it. This can lead to problems such as resource leaks as ownership of the memory is unspecified; any code can take ownership of the memory at any time. This is particularly problematic in multi-threaded applications where two threads may attempt to take ownership at the same time. If one thread releases the memory while another is still accessing that memory, undefined behaviour will occur. To avoid this, pointers to heap allocations are best encapsulated within a resource handle, a class that takes ownership of the memory. In C++, std::vector provides a thread-safe resource handle to variable-length arrays.

How do you convert decimal number 93 to binary?

To convert any number in any base to another base, simply iteratively divide by the second base, using the rules of arithmetic for the first base, recording the remainders in reverse order, until the quotient is zero. For example, answering the question of how to convert 9310 to 10111012...

93 divided by 2 is 46 remainder 1

46 divided by 2 is 23 remainder 0

23 divided by 2 is 11 remainder 1

11 divided by 2 is 5 remainder 1

5 divided by 2 is 2 remainder 1

2 divided by 2 is 1 remainder 0

1 divided by 2 is 0 remainder 1

The answer, reading the remainders from bottom to top, is 10111012.

This was not a good example, because the answer is palindromic, and can be read the same way forwards and backwards. Here is another example, converting 3710 into 1001012.

37 divided by 2 is 18 remainder 1

18 divided by 2 is 9 remainder 0

9 divided by 2 is 4 remainder 1

4 divided by 2 is 2 remainder 0

2 divided by 2 is 1 remainder 0

1 divided by 2 is 0 remainder 1

The answer is 1001012.

Why is Java not a pure OOP Language?

Java is a OOP language and it is not a pure Object Based Programming Language.

Many languages are Object Oriented. There are seven qualities to be satisfied for a programming language to be pure Object Oriented. They are:

  1. Encapsulation/Data Hiding
  2. Inheritance
  3. Polymorphism
  4. Abstraction
  5. All predefined types are objects
  6. All operations are performed by sending messages to objects
  7. All user defined types are objects.

Java is not because it supports Primitive datatype such as int, byte, long... etc, to be used, which are not objects.

Contrast with a pure OOP language like Smalltalk, where there are no primitive types, and boolean, int and methods are all objects.

Which data structure is needed to convert infix notations to pre fix notations?

S: Stack

while(more tokens)

{

x<-next token;

if(x is an operand)

print x

else

{

while(precedence(x) <= precedence(top(s))

print(pop(s))

push(s,x)

}

}

while(!empty(s))

print(pop(s));

Written by: Fabianski Benjamin

Which is the best object oriented programming language for beginners?

I would go with Python.

Python is therefore an ideal backend language due to its simplicity and consistency, where the developers are able to write reliable systems with a vast set of libraries belonging to Machine Learning, Keras, TensorFlow and Scikit-learn

How do you write a c program to generate first n natural numbers using a for loop?

#include<stdio.h>

main(void)

{

int n;

int i;

printf("Type n: ");

scanf("%d",&n);

for(i=1;i<=n;i++) //generates natural numbers from 1,....,n.

printf("%d\n",i); //prints these numbers to standard output

}

Comparison between array and dynamic implementation of linked list?

I assume you are referring to implementation of Abstract Data Types like Stacks and Queues.

Arrays have capacity limits which you set upon declaring them. If you have date which has a definite size, then using arrays is okay.

But if you have data which size changes at runtime, then just use linked lists because linked lists could constantly add nodes whenever needed.

arrays need continuous memory allocation for their creation but in linked list the memory allocation need not be continuous....

What is a enumerated data type?

An enumeration is a group of (closely) related constants of integral type (int, char, short, long or long long).

Members of an enumeration are automatically initialised with values in the order they are declared, starting with the value 0 for the first member and incrementing by 1 for each additional member:

enum traffic_light {green, amber, red}; // e.g., green=0, amber=1, red=2

If the start value 0 is undesirable, we can assign a different start value:

enum traffic_light {green=1, amber, red}; // e.g., green=1, amber=2, red=3

A new start value can be placed anywhere in an enum:

enum traffic_light {green, amber=4, red}; // e.g., green=0, amber=4, red=5

Two or more members can share the same value:

enum traffic_light {green, amber, orange=1, red}; // e.g., green=0, amber=1, orange=1, red=2

The value of a previously declared member can be used to initialise another member:

enum traffic_light {green, amber=green+1, red=green+2}; // e.g., green=0, amber=1, red=2

The names of an enumeration are within the scope of the declaration. This is often undesirable as two enumerations in the same scope cannot share the same member names:

enum traffic_light {green, amber, red};

enum rainbow {red, orange, yellow, green, blue, indigo, violet}; // error!

To avoid this, we can use an enum class. The enumeration then becomes a namespace:

enum class traffic_light {green, amber, red};

enum class rainbow {red, orange, yellow, green, blue, indigo, violet}; // ok

To refer to a member of an enum class, we use namespace resolution:

traffic_light x = red; // error! no red in scope

rainbow y = rainbow::green; // ok

What are the advantages and disadvantages of commercialization?

Commercial advertising is the process of publicising a product or service of trying to sell a product or service by drawing people's attention of the particular product.Through commercial advertising customers can easily get the information about the new product and the methods of using them.It educates them and provides a great knowledge about different products including their advantages also.They are very useful to people.Advertisements are used to build brands for the protects creates awareness among consumers before launching and introducing a new product.It develops an encouragement in the economy.

Can a continue statement be used in a switch statement?

If you have a loop in your switch statement or around your switch statement, you can use the continue statement in that. You cannot use a continue statement outside of a loop (do, for, or while).

Four basic instruction in C language?

They are 'statements' to speak strictly, they are: , , if, else, while, for, do, return, switch, break, continue, goto

Note: is zero or more statements between '{' and '}'

Which language is predecessor to C programming language?

hi everyone..

predecessor to C is B..

don think it's a joke..

in UNIX OS , the assembly code was machine dependent..

so,the version could not be portable..

so Ken Thompson rewrite the whole UNIX code in the new language called B..

But B missed several necessary aspects for real life programming..

so, Ritchie invented the new language called C which solved the inadequacies of B..

that's all...

be happy.. be cool..

Assembly language program to convert 8 bit binary to ascii code?

BinarySearch proc ;params: array (of integers), length, target

push ebp

mov ebp, esp

mov ebx, [ebp + 8]

mov ecx, [ebp + 12]

xor edx, edx

dec ecx

jmp LoopCond

LoopStart:

mov eax, edx

add eax, ecx

shr eax, 1

push ecx

mov ecx, [ebp + 16]

cmp [eax * 4 + ebx], ecx

pop ecx

je Exit

jl UpperHalf

mov ecx, eax

dec ecx

jmp LoopCond

UpperHalf:

mov edx, eax

inc edx

LoopCond:

cmp ecx, edx

jge LoopStart

mov eax, -1

Exit:

pop ebp

ret

BinarySearch endp

How do you use cosine in c language?

Include the header file math.h and use the function acos(d)

Where can a blue laser pointer be bought?

Lots of lasers are available both online and in local shop.

It would be fine to get a laser pointer from a laser shop. I am interested in laser pointer, and I have got a high power 1500mW LEVIN series blue laser pointer from LaserTo. It is pretty cool and powerful.

It is quite important to get a high performance laser pointer with reliable quality, stable operation and long lifetime. For the most important of all, quality and service are both important.

Is Basic a low level language or high level?

Dual system 1 and 0

It can also depend what you mean by computer, and how deep you want to go. You can make a "Computer" with wood and strings, as proven by the Jaquard Loom. Hardware is key, no matter how basic. So, in theory (i guess) the Basic Language would be how the computer...works! If you want to go to the very basics.

Write a program in c language to print some message on the screen with out using printf?

you can put the printf function inside a if() so that you need not use semicolons. for eg to print my name, if(printf("My Name is Maheedharan")) {} this will work. try this out...

What are reallife applications of graphs in data structures?

Applications of graph theory are primarily, but not exclusively, concerned with labeled graphs and various specializations of these.

Structures that can be represented as graphs are ubiquitous, and many problems of practical interest can be represented by graphs. The link structure of a website could be represented by a directed graph: the vertices are the web pages available at the website and a directed edge from page A to page B exists if and only if A contains a link to B. A similar approach can be taken to problems in travel, biology, computer chip design, and many other fields. The development of algorithms to handle graphs is therefore of major interest in computer science. There, the transformation of graphs is often formalized and represented by graph rewrite systems. They are either directly used or properties of the rewrite systems(e.g. confluence) are studied.

A graph structure can be extended by assigning a weight to each edge of the graph. Graphs with weights, or weighted graphs, are used to represent structures in which pairwise connections have some numerical values. For example if a graph represents a road network, the weights could represent the length of each road. A digraph with weighted edges in the context of graph theory is called a network.

Networks have many uses in the practical side of graph theory, network analysis (for example, to model and analyze traffic networks). Within network analysis, the definition of the term "network" varies, and may often refer to a simple graph.

Many applications of graph theory exist in the form of network analysis. These split broadly into three categories. Firstly, analysis to determine structural properties of a network, such as the distribution of vertex degrees and the diameter of the graph. A vast number of graph measures exist, and the production of useful ones for various domains remains an active area of research. Secondly, analysis to find a measurable quantity within the network, for example, for a transportation network, the level of vehicular flow within any portion of it. Thirdly, analysis of dynamical properties of networks.

Graph theory is also used to study molecules in chemistry and physics. In condensed matter physics, the three dimensional structure of complicated simulated atomic structures can be studied quantitatively by gathering statistics on graph-theoretic properties related to the topology of the atoms. For example, Franzblau's shortest-path (SP) rings. In chemistry a graph makes a natural model for a molecule, where vertices represent atoms and edges bonds. This approach is especially used in computer processing of molecular structures, ranging from chemical editors to database searching.

Graph theory is also widely used in sociology as a way, for example, to measure actors' prestige or to explore diffusion mechanisms, notably through the use of social network analysis software.

Likewise, graph theory is useful in biology and conservation efforts where a vertex can represent regions where certain species exist (or habitats) and the edges represent migration paths, or movement between the regions. This information is important when looking at breeding patterns or tracking the spread of disease, parasites or how changes to the movement can affect other species.

What is compaction in data structure?

The process of moving all marked nodes to one end of memory and all available memory to other end is called compaction. Algorithm which performs compaction is called compacting algorithm.

What are the basic input and output of c and c plus plus?

That is STANDARD input and STANDARD output.

By default, standard input is the keyboard, and standard output is the screen. Standard I/O is set by the operating system, though it may be redirected by script invocation or system commands within the C/C++ program itself. You could, for instance, set standard output to a printer or a file in lieu of a screen.

You should also Google Standard Error.

What is ASCII value of 0?

The ascii value of zero - is 48.

What are the various operations that can be performed on a queue?

In queue insertion takes place on rear end and deletion takes place on front end.

INSERTION(QUEUE,N,FRONT,REAR,ITEM) :QUEUE is the name of a array on which we are implementing the queue having size N.

view comlete ans at

http://mcabcanotes.in/algorithm-to-perform-insertion-and-deletion-in-a-queue/

How can a stack determine if a string is a palindrome?

foreach char in string

push on to stack

create new string

foreach char in string

pop off and add to end of new string

if new string equals old string

palindrome

else not palindrome

//when you pop off the stack, the characters come off in reverse order, thus you have reversed the original string

What is void rate?

Void ratio is defined as the ratio of the volume of the void space compared to the volume of the solid particles.

Why c language is named c?

C comes from B & B comes from BCPL........... TO overcome the problems of BCPL they developed B (First char of BCPL)....& B also has some disadvantages so they go for next level i.e, B's next Letter .........:::::::C ..........then v called it as C language. C comes from B & B comes from BCPL........... TO overcome the problems of BCPL they developed B (First char of BCPL)....& B also has some disadvantages so they go for next level i.e, B's next Letter .........:::::::C ..........then v called it as C language.