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 do you check given string is palindrome or not with out using string functions?

/*To check whether a string is palindrome*/

  1. include
  2. include
void main () {
int i,j,f=0;
char a[10];
clrscr ();
gets(a);
for (i=0;a[i]!='\0';i++)
{
}
i--;
for (j=0;a[j]!='\0';j++,i--)
{
if (a[i]!=a[j])
f=1;
}
if (f==0)
printf("string is palindrome");
else printf("string is not palindrome");
getch ();
}

What is the slowest in sorting algorithm?

There are many sorting algorithms with worst case of complexity O(n2). These algorithms have different average and best cases. They are:

Best case

Average case

Worst case

1) Quick sort

O(n*log n)

O(n*log n)

O(n2)

2) Insertion sort

O(n)

O(n2)

O(n2)

3) Bubble sort

O(n)

O(n2)

O(n2)

4) Selection sort

O(n2)

O(n2)

O(n2)

What is the difference between variable and identifier?

An identifier is simply the name of something, while a variable is an instance of something.

For example:

int x;

Here, the identifier is "x," but the variable is the object whose name is "x." A: An identifier is a name of something. Typically used in computer programming, the term "identifier" is frequently used to name a variable (see below), a subroutine, are in reality, any place in memory in which data or code reside where a name would be useful. "MyBirthDate" might be a good identifier, pointing to a memory location where the data contianing your date of birth is stored. The term variable comes to us from mathematics, but is frequently used in computer science too. It refers to a value that varies. For instance: a + b = 5 In this case, the value of a and b can change, so long as the sum of a and b equal 5. The opposite of the term variable is constant. In the equation, E=Mc2, c is a constant that is equal to the speed of light in a vacu -- +- 186,000 miles per second. In computer science, the term "variable" is used synonymously with "identifier" when they are both used to point to memory that contains data that may be changed and will not always be the same. In Microsoft BASIC, the statement: Tomorrow = Today + 1 Today and Tomorrow are variables, and 1 is a constant.

How do you write a floating point variable in c?

You declare a floating point variable using the float or double keyword for a single- or double-precision floating point variable, respectively:

float a;

double b;

You reference a floating-point variable just like any other scalar variable by using the variable's name in a compatible expression, e.g.

a += 2;

b /= a;

Floating point literals use a period for the decimal point, no "thousands separator," and use the letter 'e' to denote a power of ten, e.g.

a = 0.123;

b = 123e-3;

Both a and b now have the same value, 123 times 10 to the power of -3 (which equals 0.123).

What is a valid c plus plus identifier?

In C++ we provide names for the entities we create, the variables, functions and types in our programs. These names, or identifiers, are required to conform to some simple rules.


An identifier must start with a letter and is comprised of a sequence of letters and digits. Somewhat surprisingly, in this context the underscore _ is considered to be a letter (although there are conditions associated with its use). There's no restriction on the length of an identifier.

What is the difference between tree search and graph search?

A graph is a set of vertices which are connected to each other via a set of edges.

A tree is a special type of hierarchical graph in which each node may have exactly one "parent" node and any number of "child" nodes, where a parent node is one level closer to the root and a child node is one level further away from the root.

Write a C plus plus program that asks the user to enter five numbers?

When writing a program that expects to retrieve data from a user, you have to first know what kind of interface to use. Decide whether you wish to write a console or windowed (graphical) application.

For console applications, you would likely use the scanf() function to retrieve values. See the help system for your compiler or look up "scanf" on the Web for details on using this function.

Graphical applications depend upon the operating system you're using. For instance, under Win32, you have the following options:

- Design a dialog at runtime consisting of STATIC and EDIT controls, plus a BUTTON control for the user to tell your program to commit the data, created with the CreateWindow() or CreateWindowEx() functions;

- If you're using an IDE (i.e. VC), it probably came with a resource editor you can use to create a dialog that contains labels and edit controls.

If you're brave enough to attempt some X11 coding, you'll need to decide which window manager you're using, and read up on the API for that WM to know which functions you have at your disposal.

You will also need to store this data in variables and then act on those variables as desired.

Where the phased locked loop is used?

Phase lock loop is used in analog and digital communications to keep the phase of the output signal the same as the input signal.

What are the books to study C Plus Plus?

Smart-C: Complete Programming Book available on Flipkart (Rating - 5 Star)

The book deals with one such Great programming language “C”. The book is designed to help the reader program in C. Great care has been taken in making the content interesting and understandable. Each module is added with multiple graphic images to make content easily understandable

Rules in naming variables in programming?

there are various types of naming rule provide for function ,identifier,i.e variables.but naming rule for variable must meet certain condition..

1.you can easily idenfy what is variable for.for eg.you may use

int a;/to store no of student in your prog. but it is better instead of using "a",you can write any of the following definition

int stu; or int stu_no; or int studentno;

2.it must be abbreviated.because although modern compiler support 32 char variable but still where you use that variable you have to type that name again &again.

so for eg. in the above case int stu_no; is optimal.

when these precondition are met then here are some rules for naming a variable:

1.you use only English alphabet,numeric no,& _(underscore).

2.you must start with a alphabet. then you continue with alphabet or numeric or under score.for eg. you can define a variable like

int stu_comp_2009;//for no of student 2009 batch.

3.no variable can start with number or _.such naming may cause some compiler do the right job but maximum would not support this.

Reverse of a given string using recursion?

#include <stdio.h>

#include <conio.h>

#include <string.h>

void main()

{

char str[10],temp;

int i,len;

printf("Enter String : ");

scanf("%s",str);

len=strlen(str)-1;

for(i=0;i<strlen(str)/2;i++)

{

temp=str[i];

str[i]=str[len];

str[len--]=temp;

}

printf("%s",str);

getch();

}

Please do give your views on this.

With Regards,

Sumit Ranjan.

Analyst at RMSI Company.

What is the purpose of program counter?

program counter is a register that has the address of next instruction that has to be executed after currently executing instruction. it is used for proper execution of functions of computer by providing address of next instruction to microprocessor.

How do you write a program to sort an array using selection sort?

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int n,i,j,temp,a[50];

printf("Enter how many elements=");

scanf("%d",&n);

printf("Enter %d elements",n);

for(i=1;i<=n;i++)

{

scanf("%d",&a[i]);

}

for(i=1;i<=n-1;i++)

{

for(j=1;j<=n-1;j++)

{

if(a[j]>a[j+1])

{

temp=a[j];

a[j]=a[j+1];

a[j+1]=temp;

}

}

}

printf("\nSorted Array:\n");

for(i=1;i<=n;i++)

{

printf("\n%d",a[i]);

}

getch();

}

What expression has a value of either true or false?

In C, any non-zero expression is true and any zero expression is false.

What are the benefits of enumeration types?

We use enumerations to identify a group of constants in a more meaningful way than would be possible with an integral type. Consider the following:

int toggle (int traffic_light)

{

if (traffic_light<0 traffic_light>3) return -1; // invalid argument!

traffic_light=traffic_light==3?0:traffic_light+1;

return traffic_light;

}

The int argument, traffic_light, gives us some indication as to its purpose, but the body of the function is difficult to read. It's difficult to digest the logic and the literal constant 3 looks suspiciously like a "magic number". Worse, the function returns errors through the return value.

Let's re-write the function with an enumerated type:

enum traffic_light {green, amber, red, red_amber};

traffic_light toggle (traffic_light current)

{

switch (current)

{

case green: current=amber; break;

case amber: current=red; break;

case red: current=red_amber; break;

default: current=green;

}

return current;

}

While the body of the function is more verbose, the logic is much clearer. We can see from the enumeration that a traffic_light object only has four possible states and that the function cycles from one state to the next, just as a real traffic light should.

Upon closer examination, we note that a traffic_light behaves exactly as if it we're a 2-bit unsigned integer and that all we're doing is incrementing the integer, cycling back to 0 when both bits are set. So we could effectively implement the toggle function with an operator overload:

traffic_light& operator++(traffic_light& lhs)

{

return lhs = (lhs==red_amber)?green:(traffic_light)(((int) lhs)+1);

}

Operator overloads are often difficult to read, however all operators must be intuitive; they should all work exactly as we expect them to work. The above actually replicates the middle line of the original function, casting to int to perform the increment.

With this in place, our toggle function becomes:

traffic_light toggle (traffic_light current)

{

return ++current;

}

What is a macro and its advantages?

Macros are preprocessor statements which will have specific set of instructions which are repeated in source code for several times and which wil be replaced at every call made.

1. Reduce source code length

2. Prog more readable.

3. Any modification to instructions in macro reflects in every call

4. No performance drawback by macros

1. Every call will be replaced and hence internally code length will be large.

Are the expressions 'arr' and ' and arr' are same for an array of integers?

No arr refers to address of array &arr refers address of address of array but compiler treats arr and & arr, so even you place arr and & arr no error only warnings will be displayed.

Can a Volatile variable be static also?

Probably; I don't see anything in the standard that says you can't. However, the use of the volatile keyword is usually in embedded code, or multi-threading in which you don't want the compiler to do optimizations on the variable itself.

Yes, sure.

What is next fit algorithm?

Memory is used more evenly because the search for a free partition does not always start at the beginning of the list (forcing higher use of these partitions and lower use of the partitions at the end of the list).

What is integer type array?

An array is a collection of similar data types. An integer array is nothing but a collection of integer data types.

Ex: int a[100], int arr[100][100]

There are several types. 1D array, 2D array, Multi-Dimensional array.

But array is a contiguous allocation. And array size will always be positive. It can be given in the declaration stage or we can specify it dynamically by using malloc function.

Ex: int *a;

a=(int*)malloc(sizeof(int)*HOW_MANY_NUMBERS_YOU_WANT);

How you can access data member inside the main program in c plus plus programming language?

Public, protected and private accessors only apply to code outside of the class. Instances of a class (objects) have complete and unrestricted access to all their own instance variables (data members). They also have unrestricted access to the instance members of all other instances of the same class whenever those instances are passed as arguments to a class member method. Static methods of the class have the same privilege, as do friends of the class.

So the question isn't why an object can access its own public members without using an operator or member function. Any code outside of the class has that exact same right, but if an object has unrestricted access to its protected and private members, why should its public members be treated any differently?

How does C compiler work?

C is a programming language.

Compiler is used to convert our source code which is in high-level language or human understandable code into machine language. Compiled source code can be executed any where once if it is compiled .

Is Microsoft Word an input device?

"An Input device is any piece of computer hardware equipment used to provide data and control signals to an information processing system (such as a computer). Input and output devices make up the hardware interface between a computer and the user or external world " - Wikipedia Egs. Keyboard , mouse etc. Whereas, MSWord is part of the Microsoft office which is an application s/w introduced by Microsoft in 1989. So, obviously it's not a DEVICE!

Is if else a loop or not?

No such thing as 'if-loop', you can choose from:

while (expression) statement

for (expression; expression; expression) statement

do statement while (expression)