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

Why there is only one main function in every C programmes?

Try putting 2 main functions in a program and see what happens rather than asking easy for you to resolve questions here.

What do you mean by variable in c?

scope of a variable is the part of the code within which the variable is defined or the part of your code within which the th variable can be used for example

#include<stdio.h>

void main()

{

int variable1

}

now this variable (variable1) that we have used can be used anywhere within the main function .but if i write a code as shown below

#include<stdio.h>

void function1(int a)

void main()

{

int variable1

}

void function1(int a)

{

sum=variable1+variable1;

}

the compiler wouldn't know what variable1 ,being used in function1 is.

we therefore say that variable1 has a scope within the main only

if however we would have written int 'variable1' immediately after #include<stdio.h> then 'variable one would have been a global variable and could have been used anywhere within the code

What is the major components of c programming?

The major components of a class are its members (data and methods) and its interface to those members. All classes have four members by default: the default constructor, the copy constructor, the destructor, and the assignment operator. However, if you declare any constructor (including a copy constructor) you lose the default constructor unless you declare your own. The class interface is defined by the public, protected and private sections of the class declaration. The interface may also be extended via friend classes and friend functions. Public and protected interfaces can also be inherited from existing base classes and/or abstract base classes to create derived classes, which may modify the base class interfaces without altering the base class itself. Private members can never be inherited, however.

The interface can be divided into several key components: construction, destruction, operations, attributes, accessors and mutators. Constructors handle the complete initialisation of the class and every constructor must ensure that a valid object exists whenever an object of the class is instantiated. The destructor is purely responsible for cleaning up any dynamic memory allocated on the heap and owned by the class (memory allocated on the stack is always released automatically). Operations include the assignment operator and any other operator overloads that modify the class in some way, such as the prefix increment operator. Attributes include type-casts and boolean operators such as the equality and greater-than operators, plus any member methods that return information about the class. Accessors return specific member values from the class (getters) while mutators modify those same members (setters).

Why cin and cout are iostream objects?

Most programs require both input and output. By including iostream you gain access to both, along with the most common datatypes and functions within the standard library. If you don't require all the features provided, you can include only what you need instead.

What do you mean by function to pointer?

Answer
  • I take it you are using some version of c,c++,visualC etc etc. One thing that is standard is pointers. A pointer is the address of a memory space that holds information in that specific space. By referencing the pointer in your code, you can print out that specific bit of information that the poiner is actually pointing to. Hope this helps

Detailed difference between structure and array?

1). Structuer is a group of diffrent data type & set of diff. data type element can manupulet by using structuer .It Size is Addition of all Data type size e.g(int,float,char*2+4+1) =7 byte size of structure

2.) Array is Collection of Same data Type Element

it is intege Array , Char Array , ponter Array,Objeact Array etc,

What is the while loop in C programming?

"while" is an entry controlled loop statement i.e the condition is evaluated first and if it is true the body of the loop is evaluated.This process is repeated until the test condition is false;then the control is transfered out of the loop.

The general form of while is as following

syntax:

while (<condition>)

{

<statements>;

}

Disadvantages of macros in c language?

Actually macro and function are used for diff purposes.A macro replaces its expression code phisically in the code at the time of preprocessing.But in case of function the control goes to the function while executing the code.
So when the code is small then it is better to use macro.But when code is large then function should be used.

If you could get any help from the answer then plz increase my trust point.

Which data structure is used in relational model?

The correct term is "What are data structures in database management systems?"

Please learn how to speak English

~Sincerely

The Hacker

What is a value that is passed into a method when it is called?

Here is an example program that passes a Scanner object:

import java.util.*;

public class Conversion

{

public static void main(String[] args)

{

Scanner in = new Scanner(System.in);

doSomething(in);

}

public static void doSomething(Scanner in)

{

int q = in.nextInt();

System.out.println("The value you entered is: " + q);

}

}

Formula to convert binary to decimal and decimal to binary?

I do not know a specific formula to do it. but its very simple. really really simple

lets get a binary code = 10011101

now, we are going to convert this to decimal. You should start it from the last binary number in the given code,(right hand corner)

then multiply that number from 2 to the power of 0( 2^0)

1* (2^0) = 1* 1 = 1 --------- (A)

then we go to the next binary number. (which is 0 in this case)

now we must multiply this from 2 to the power 1. (2^1);

0 * (2^1) = 0* 2 = 0 --------(B)

do this sequentially till the first number. (multiplying from 2^2,2^3,...,2^7)

similarly you get,

1 * (2^2) = 4 ----(C)

1 * (2^3) = 8 ----(D)

1 * (2^4) = 16 ----(E)

0 * (2^5) = 0 ------(F)

0 * (2^6) = 0-----(G)

1 * (2^7) = 128----(H)

now, add the values you got in equation A,B,C,D,E,F,G,H

1+0+4+8+16+0+0+128 = 157; so this is the decimal number for the given binary code.

hope you got it!!

How do you find the minimum value of an array in c language?

Your best bet would probably be to iterate through the array using a for loop and compare each value to the current low and high values (which you would store in a local variable)

for example:

for each element in array

{

if current is less than lowest_value

lowest_value = current

else if current is greater than highest_value

highest_value = current

}

What is function in C plus plus programming language?

Functions are short procedures or subroutines that can be called as and when required. Unlike goto statements, which branch off to a labelled section of code never to return, functions always return back to the caller. Functions may also call other functions. Functions are typically used to reduce the amount of duplicate code, producing more consistent and error-free code and reducing maintenance whenever functions need to be modified. Functions are also used to make code more readable by replacing complex or compound statements with a simpler function call. By using easy to understand function names, code becomes self-documenting, reducing the need to include verbose comments that only serve to interrupt the flow of the code.

Although there is a performance penalty in calling functions as opposed to inline code, the compiler's optimisation routines can inline expand functions whenever there is an advantage in doing so. Typically this applies to short functions with one or two simple statements, but can also apply to functions that are seldom called.

Functions may also return a value back to the caller (a function that does not return a value simply returns void). Functions can modify their behaviour according to arguments supplied to the function. The number and type of arguments is dependant upon the function signature. The signature also differentiates between functions with the same name, thus allowing functions to be overloaded to cater for different arguments types.

If the argument types are references (or pointers), the function can modify the arguments passed to it unless the arguments are declared const. Passing by reference also allows functions to return more than one value to the caller (typically the return value itself is used to provide diagnostics, such as an error code).

If the arguments are passed by value, however, the function creates a local copy of the argument, thus preventing changes to the argument that was actually passed. If the argument being passed is an object, the object's copy constructor is called automatically. Since this can be detrimental to performance, objects should always be passed by reference unless the function actually needs to work on a copy of the object rather than the original object.

In C++, classes make use of functions, known as member methods, to provide the implementation of operations that may be applied to an object's data. Classes may also employ virtual functions that allow derived objects to provide more specialised implementations whilst retaining the existing generic code. This also helps to reduce duplicate code, but also allows objects to behave polymorphically. That is, it is not necessary for a generic class to know any of the implementation details of its derivatives. You simply call the generic method of the base class and the virtual table redirects the call to the most-specialised override of that function, if one exists. If not, the generic method is called instead. Classes can also make use of pure-virtual functions, such that the base class need not provide any generic implementation at all. These classes are abstract classes which cannot be instantiated by themselves. Instead, you are expected to derive new classes from abstract classes, and the derived classes must provide the implementation even if the base class provides a generic implementation. Only classes that provide or inherit a complete implementation of all pure-virtual methods can actually be instantiated.

Similarities between Structured programming and object oriented programming?

Both types of programming utilize algorithms when processing data. Procedural and object oriented programming will also logically compute the tasks assigned to it using different programming languages.

What is the difference between error and warning message in c?

Warnings and errors are both errors in C++, but warnings won't prevent your program from compiling, whereas errors will. Some warnings may be unavoidable in the interest of optimising performance, but so long as they do not affect the program's operations they can often be ignored. For instance, casting an unsigned char to a signed char has potential for loss of data if the unsigned char is greater than 127, and is therefore an unsafe cast. But if you can assert the cast is safe then the warning can be ignored. The alternative would be to cast to a larger type (such as casting to a signed short), but this might result in large changes to your program where a signed char is expected. As programmer, you are free to decide whether the warning really should be treated as an error, or if the warning can be safely ignored with prudent assertions instead.

Write a program to print the table of any number using two dimensional array in c program?

/* PROGRAMME TO PRINT THE TABLE OF A GIVEN NUMBER USING FUNCTION */
#include
#include


void table(int,int);
void main(void)
{
int num,i;
printf("\n Programme to print the mathematical table of a number.");
printf("\n Enter the number : ");
scanf("%d",&num);
printf("\n Upto how many multiples of the given number do you want? ");
scanf("%d",&i);
table(num,i);
getch();
}


void table(int num,int i)
{
for(int j=1;j<=i;j++)
printf("\n %5d * %5d = %5d",j,num,j*num);
}

Write Java program to display largest of 3 numbers?

//i hope its something like this you want

import java.util.*;

public class Count

{

public static void main(String args[])

{

double numbers;

Scanner scan;

int counter;

numbers=0;

scan=new Scanner(System.in);

for(counter=1; counter<=10; counter++)

{

System.out.println("Please enter numbers");

numbers=scan.nextDouble();

{

System.out.println("The number is "+numbers++);

}

}

}

}

How do you represent stack and queue by using one dimensional array?

You would not use an array for a stack or queue, you would use a singly-linked list. The problem with arrays is that they must grow and shrink as items are inserted or extracted, which requires the entire array to be copied, whereas linked-lists can grow and shrink dynamically without the need to copy any elements. The only reason to use an array to implement a list is when you require random access in constant time. Queues and stacks only require constant time access to the head or tail of the list, and a linked list can easily achieve that.

Implementing a stack as an array requires that new elements be inserted at the end of the array. If the array is full, it must be reallocated in order to make space for a new element. Extraction always occurs at the end of the array. While this releases elements for insertions, if they go unused for any length of time they are simply wasting memory. Thus the array must be reallocated occasionally to free the redundant memory, which is highly inefficient.

Implementing a queue has similar issues as all insertions are at the end of the array, however it is further complicated by the fact extractions must occur at the beginning of the array. Thus every element must be copied to its preceding element every time an element is removed from the head of the queue. This frees up the end of the array, but the need to reallocate and copy elements is again, highly inefficient.

Linked lists overcome all these problems such that no memory is ever in a redundant state, and no copying is ever required.

Source code for multilevel queue program in Java?

import java.io.*;

import java.util.*;

public class QueueImplement{

LinkedList<Integer> list;

String str;

int num;

public static void main(String[] args){

QueueImplement q = new QueueImplement();

}

public QueueImplement(){

try{

list = new LinkedList<Integer>();

InputStreamReader ir = new InputStreamReader(System.in);

BufferedReader bf = new BufferedReader(ir);

System.out.println("Enter number of elements : ");

str = bf.readLine();

if((num = Integer.parseInt(str)) == 0){

System.out.println("You have entered either zero/null.");

System.exit(0);

}

else{

System.out.println("Enter elements : ");

for(int i = 0; i < num; i++){

str = bf.readLine();

int n = Integer.parseInt(str);

list.add(n);

}

}

System.out.println("First element :" + list.removeFirst());

System.out.println("Last element :" + list.removeLast());

System.out.println("Rest elements in the list :");

while(!list.isEmpty()){

System.out.print(list.remove() + "\t");

}

}

catch(IOException e){

System.out.println(e.getMessage() + " is not a legal entry.");

System.exit(0);

}

}

}

Fullform of computer?

A computer is a person or a machine that performs computations. An accountant is a computer (human computer). A slide-rule is a computer (an analog computer). A smart phone is a computer (digital computer).

Program to find reverse of given number using pointers?

#include

#include

void main()

{

int rev num=0;

while(num>0)

{

rev num=rev num*10+num%10;

num=num%10;

}

return rev_num;

}

int main();

{

int num=4562;

printf("reverse of number is%d",reverse digit(num));

getch();

return o;

}

What is storage claases in c language?

storage classes is important part of c language.WHENEVER we define any function in c program then we can call that in every definend class.

there are four types of storage class. these are...

1 AUTO OR AUTOMATIC STORAGE CLASS

2 REGISTER STORAGE CLASS

3 STATIC STORAGE CLASS

4 EXTERNALSTORAGE CLASS

1) The features of "AUTOMETIC" storage class are as under some conditions:

storage : storage will be in memory.

value : garbage value.

scope : scope is local to block to the variable.

life : till, controls remain within the block.

2) The featurs of "STATIC" storage class are as under some conditions:

storage : memory.

value : zero.

scope : local to block.

life : Till control remains within the block.

3) The featurs of "REGISTER" storage class are as under some conditions:

storage : register.

value : garbage value.

scope : local to the block.

life : value persists between variable.

4) The feature of "EXTERNAL" storage class are as under some conditions:

storage : memory.

value : zero.

scope : local to block.

life : till controls remains within the block.

What is the use of 'pragma' in C language?

The #pragma directive is a compiler specific instruction. There are many things you can tell the compiler. For instance, the #pragma pack n directive tells the compiler to override the /Zpn command line argument and to use a new default structure packing value. To see all of the possible #pragma directives, go to online help, and index by #pragma directives, C/C++. You probably only need to type in #pra and then click on C/C++ to get this far.

Why does your 3 phase compressor run backwards some times?

a three phase motor is reversed by switching 2 of the 3 power leads (any two) something is switching the power leads on you