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

What is the operator that cannot be overloaded?

There are 5 operators which cannot be overloaded. They are:

* .* - class member access operator

* :: - scope resolution operator

* . - dot operator

* ?:: - conditional operator

* Sizeof() - operator Note:- This is possible only in C++.

What is a universal pointer?

A universal pointer is a pointer variable that does not specify the type being pointed at. That is, it can be used to store any memory address regardless of the type of object actually stored at that address. It can be likened to a variable type, but you cannot dereference the memory address without providing some mechanism for determining the actual type stored at that memory address. Generally you would use a universal pointer when you don't actually care what type resides at the address, you are only interested in the address itself. But just as a typed pointer can point to 0 (or NULL), so can a universal pointer, which simply means it points at nothing at all.

How do you find the fectorial in C programming?

#include<stdio.h>

#include<conio.h>

void main()

{

int fact,f;

printf("Enter number");

scanf("%d",&f);

fact=1;

while(f>1)

{

fact=fact*f;

f--;

}

printf("Factorial is: %d",fact);

}

Advantages and disadvantages of algorithm?

The advantages of algorithms are:

1.They are easy to understand

2.They are easy to implement

3.They are easy to modify

4.They are not dependent on any particular computer language.

What are the advantages and disadvantages of using cellphones?

The advantages of using cellphones are so many including mobility and convenience. However, there are many disadvantages as well which includes health hazards as a result of cellphones being electromagnetic devices.

Why use new and delete operator overloading in c plus plus?

one reason to use new and delete operator overloading in c++ is when you are using your own memory manager code. when the user of your code calls the new keywork, your memory manager code can allocate memory.

Virus written in C?

And by the way, I know that "most virus' are written in Asm, and not any high level languages cuz they're too... uh... high, yeah. stupid f*ckin computer geeks, go jump off 21h and land in the stack. anyway, yes, my question (I am Agrybard) is really if there are any virus' written in C++, rather than just C, but either way I would appreciate any help. and yes, I've GOOGLED IT ALREADY! lol AGB

Explain string handling in C with examples?

In this tutorial you will learn about Initializing Strings, Reading Strings from the terminal, Writing strings to screen, Arithmetic operations on characters, String operations (string.h), Strlen() function, strcat() function, strcmp function, strcmpi() function, strcpy() function, strlwr () function, strrev() function and strupr() function.

A string is a sequence of characters. Any sequence or set of characters defined within double quotation symbols is a constant string. In c it is required to do some meaningful operations on strings they are:

  • Reading string displaying strings
  • Combining or concatenating strings
  • Copying one string to another.
  • Comparing string & checking whether they are equal
  • Extraction of a portion of a string

Strings are stored in memory as ASCII codes of characters that make up the string appended with'\0'(ASCII value of null). Normally each character is stored in one byte, successive characters are stored in successive bytes.

Character

m

y

a

g

e

i

s

ASCII Code

77

121

32

97

103

10

32

105

115

Character

2

(

t

w

o

)

\0

ASCII Code

32

50

32

40

116

119

41

0

0

The last character is the null character having ASCII value zero.

Initializing Strings

Following the discussion on characters arrays, the initialization of a string must the following form which is simpler to one dimension array.

char month1[ ]={'j','a','n','u','a','r','y'};

Then the string month is initializing to January. This is perfectly valid but C offers a special way to initialize strings. The above string can be initialized char month1[]="January"; The characters of the string are enclosed within a part of double quotes. The compiler takes care of string enclosed within a pair of a double quotes. The compiler takes care of storing the ASCII codes of characters of the string in the memory and also stores the null terminator in the end.

/*String.c string variable*/

#include < stdio.h >

main()

{

char month[15];

printf ("Enter the string");

gets (month);

printf ("The string entered is %s", month);

}

In this example string is stored in the character variable month the string is displayed in the statement.

printf("The string entered is %s", month");

It is one dimension array. Each character occupies a byte. A null character (\0) that has the ASCII value 0 terminates the string. The figure shows the storage of string January in the memory recall that \0 specifies a single character whose ASCII value is zero.

J

A

N

U

A

R

Y

\0

Character string terminated by a null character '\0'.

A string variable is any valid C variable name & is always declared as an array. The general form of declaration of a string variable is

Char string_name[size];

The size determines the number of characters in the string name.

Example:

char month[10];

char address[100];

The size of the array should be one byte more than the actual space occupied by the string since the complier appends a null character at the end of the string.

Reading Strings from the terminal:

The function scanf with %s format specification is needed to read the character string from the terminal.

Example:

char address[15];

scanf("%s",address);

Scanf statement has a draw back it just terminates the statement as soon as it finds a blank space, suppose if we type the string new york then only the string new will be read and since there is a blank space after word "new" it will terminate the string.

Note that we can use the scanf without the ampersand symbol before the variable name.

In many applications it is required to process text by reading an entire line of text from the terminal.

The function getchar can be used repeatedly to read a sequence of successive single characters and store it in the array.

We cannot manipulate strings since C does not provide any operators for string. For instance we cannot assign one string to another directly.

For example:

String="xyz";

String1=string2;

Are not valid. To copy the chars in one string to another string we may do so on a character to character basis.

Writing strings to screen:

The printf statement along with format specifier %s to print strings on to the screen. The format %s can be used to display an array of characters that is terminated by the null character for example printf("%s",name); can be used to display the entire contents of the array name.

Arithmetic operations on characters:

We can also manipulate the characters as we manipulate numbers in c language. When ever the system encounters the character data it is automatically converted into a integer value by the system. We can represent a character as a interface by using the following method.

X='a';

Printf("%d\n",x);

Will display 97 on the screen. Arithmetic operations can also be performed on characters for example x='z'-1; is a valid statement. The ASCII value of 'z' is 122 the statement the therefore will assign 121 to variable x.

It is also possible to use character constants in relational expressions for example

ch>'a' && ch < = 'z' will check whether the character stored in variable ch is a lower case letter. A character digit can also be converted into its equivalent integer value suppose un the expression a=character-'1'; where a is defined as an integer variable & character contains value 8 then a= ASCII value of 8 ASCII value '1'=56-49=7.

We can also get the support of the c library function to converts a string of digits into their equivalent integer values the general format of the function in x=atoi(string) here x is an integer variable & string is a character array containing string of digits.

String operations (string.h)

C language recognizes that string is a different class of array by letting us input and output the array as a unit and are terminated by null character. C library supports a large number of string handling functions that can be used to array out many o f the string manipulations such as:

  • Length (number of characters in the string).
  • Concatentation (adding two are more strings)
  • Comparing two strings.
  • Substring (Extract substring from a given string)
  • Copy(copies one string over another)

To do all the operations described here it is essential to include string.h library header file in the program.

strlen() function:

This function counts and returns the number of characters in a string. The length does not include a null character.

Syntax n=strlen(string);

Where n is integer variable. Which receives the value of length of the string.

Example

length=strlen("Hollywood");

The function will assign number of characters 9 in the string to a integer variable length.

/*writr a c program to find the length of the string using strlen() function*/

#include < stdio.h >

include < string.h >

void main()

{

char name[100];

int length;

printf("Enter the string");

gets(name);

length=strlen(name);

printf("\nNumber of characters in the string is=%d",length);

}

strcat() function:

when you combine two strings, you add the characters of one string to the end of other string. This process is called concatenation. The strcat() function joins 2 strings together. It takes the following form

strcat(string1,string2)

string1 & string2 are character arrays. When the function strcat is executed string2 is appended to string1. the string at string2 remains unchanged.

Example

strcpy(string1,"sri");

strcpy(string2,"Bhagavan");

Printf("%s",strcat(string1,string2);

From the above program segment the value of string1 becomes sribhagavan. The string at str2 remains unchanged as bhagawan.

strcmp function:

In c you cannot directly compare the value of 2 strings in a condition like if(string1==string2)

Most libraries however contain the strcmp() function, which returns a zero if 2 strings are equal, or a non zero number if the strings are not the same. The syntax of strcmp() is given below:

Strcmp(string1,string2)

String1 & string2 may be string variables or string constants. String1, & string2 may be string variables or string constants some computers return a negative if the string1 is alphabetically less than the second and a positive number if the string is greater than the second.

Example:

strcmp("Newyork","Newyork") will return zero because 2 strings are equal.

strcmp("their","there") will return a 9 which is the numeric difference between ASCII 'i' and ASCII 'r'.

strcmp("The", "the") will return 32 which is the numeric difference between ASCII "T" & ASCII "t".

strcmpi() function

This function is same as strcmp() which compares 2 strings but not case sensitive.

Example

strcmpi("THE","the"); will return 0.

strcpy() function:

C does not allow you to assign the characters to a string directly as in the statement name="Robert";

Instead use the strcpy(0 function found in most compilers the syntax of the function is illustrated below.

strcpy(string1,string2);

Strcpy function assigns the contents of string2 to string1. string2 may be a character array variable or a string constant.

strcpy(Name,"Robert");

In the above example Robert is assigned to the string called name.

strlwr () function:

This function converts all characters in a string from uppercase to lowercase.

syntax

strlwr(string);

strrev() function:

This function reverses the characters in a string.

Syntax

strrev(string);

For ex strrev("program") reverses the characters in a string into "margrop".

strupr() function:

This function converts all characters in a string from lower case to uppercase.

Syntax

strupr(string);

For example strupr("exforsys") will convert the string to EXFORSYS.

/* Example program to use string functions*/

#include < stdio.h >

#include < string.h >

void main()

{

char s1[20],s2[20],s3[20];

int x,l1,l2,l3;

printf("Enter the strings");

scanf("%s%s",s1,s2);

x=strcmp(s1,s2);

if(x!=0)

{printf("\nStrings are not equal\n");

strcat(s1,s2);

}

else

printf("\nStrings are equal");

strcpy(s3,s1);

l1=strlen(s1);

l2=strlen(s2);

l3=strlen(s3);

printf("\ns1=%s\t length=%d characters\n",s1,l1);

printf("\ns2=%s\t length=%d characters\n",s2,l2);

printf("\ns3=%s\t length=%d characters\n",s3,l3);

}

How does a compiler convert high to low level language?

It depends on the compiler and operating system. A lot of compilers generate C(++) objects or code instead of assembly language. It seems to be easier for compiler developers to develop and support a C(++) platform instead of assembler.

What is low level language?

Computer programming languages are divided into 2 types: low level languages and high level languages. There are 2 low level languages machine language and assembly language.

Machine language consists of two digits 0 and 1. 0 represents off and 1 represents on. These are called binary digits. 8 bits form 1 byte. Each byte represents a letter. For example A is represented by 01000001.

assembly language is easier than machine language. It has short words or abbreviations like ORG, MOVLW, GOTO.

What is the meaning of percent a in c language?

This is found in the printf family of functions. The % is just a flag that says that the next character specifies a variable type.

%c character

%d signed integers

%i signed integers

%e scientific notation, with a lowercase "e"

%E scientific notation, with a uppercase "E"

%f floating point

%g use %e or %f, whichever is shorter

%G use %E or %f, whichever is shorter

%o octal

%s a string of characters

%u unsigned integer

%x unsigned hexadecimal, with lowercase letters

%X unsigned hexadecimal, with uppercase letters

%p a pointer

%n the argument shall be a pointer to an integer into which is placed the number of characters written so far

%% a '%' sign

What is the task of creating accurate operator permit IDs dependent on?

The standardized GCSS-Army directory for selecting all Equipment and Utilization Training qualifications is called the ________.

Write the Algorithm of inserting an element at middle of linked list?

I am telling you the algorithm of inserting an element at any location of simply link list:-


insert_loc(start,item,loc)

step1. [Check for overflow]
if ptr=NULL
then print overflow
exit
else
[ptr=(node*) malloc (size of nodes)] {memory allocation}

step2. set ptr->info=item
step3. set i=1
set temp=start
step4. Repeat step 5&6 until istep5. set temp=temp->next
step6. set i=i+1
step7. set ptr->next=temp->next
step8. set temp->next=ptr

Good luck

Rjames007

What language is used by assembler?

Assembly languages vary by the intended architecture.

In general, assembly languages are very basic when compared to higher level languages like C, Java, Perl or Python, consisting of only a few dozen instructions. These instructions are grouped together to form higher level operations. Generally, it takes many lines of assembly code to do the same task as a few lines of higher level code.

Variables are not 'named' like in high level languages and are limited in quantity. However, greater control over storage locations can be acheived. For instance, r0 would refer to a variable stored in register 0. Mathematic operations are often performed by logical operations (AND, OR, XOR etc etc).

What is the function of keywords in the C language?

Keywords are reserved words in a programming language whose meaning are available in the respective compiler. C programming language has the following keywords; default, return, struct, void, volatile, unsigned, signed, double, while, union, static, switch, typedef, register, short, size of, for, long, if, int, goto, enum, float, else, extern, do, const, break, char, case, break and auto.

What are the differences between a global variable and macro?

A global variable is a place of data storage which multiple modules of application (sometimes all modules) can access to read and modify the variable's content.

A macro is something altogether different. A macro is a set of instructions, typically used to save keystrokes when coding, and to maintain code readability. While macros can reference, declare or use variables (including global variables), macros and variables are quite different and cannot be compared.

Draw a flowchart that will determine and display the largest among the three numbers being inputted?

start

input A & B

if A>B print A is greatest

if B>A print B is greatest

stop

james ola writes.....SOT.

How many hours should a student study?

In my opinion, no stuent or any other worker should be expected to work for more than 7 1/2 hours a day, five days a week over 48 weeks a year. That would be 1500 hours a year, or about 50 hours a week in a three-term, ten week term year. For a school student, that is a 40 hour week over a 48 week year. For young people under 16, clearly the study time should be reduced.

What is the use of pointer in c?

A double pointer in C or C++ ...

int ** ppi;

... simply means that ppi is a pointer that points to a pointer that points to an int.

When defining function-parameters, another way of declaring this is ...

int * ppi[];

... which means that ppi is a pointer to an array of pointers that each point to an int, which happens to have the exact same meaning, but it is more telling in terms of what the usefulness of such a double pointer might have.

Think of main() ...

int main (int agrc, char ** argv);

int main (int argc, char * argv[]);

... the two forms have exactly the same meaning, but the second form more clearly says what the design paradigm is, that argv is a pointer to an array of pointers that each point to an array of char, i.e. the arguments of the program's invocation.

Difference between linear n nonlinear data structures?

A data structure is linear if every item is related (or attatched) to its previous and next item(e.g.array, linked list) and it is non-linear if every item is attached to many other items in specific ways to reflect relationships(e.g, n-ary tree). In linear data structure data items are arranged in a linear sequence. In non-linear data structure data items are not in a sequence.

A different Opinion (learnt while watching a video on Data Structures) is that Linear data structures are the Data structures implemented using arrays (with consecutive data allocation for each member of the array) while Non Linear Data Structure refers to an implementation in terms of use of pointers (such as a linked list).

--Research Reqd.--

What is the use of new operator?

A new operater is used to allocating a memory space for a particular object.

What are the good characteristics of an algorithm?

1 simple but powerful and generalsolutions

2 can be easily understood by others

3 can be easily modified if necessary

4 correct for clearly defined situation

5 understood on a number of levels

By Amol Dhagdi

What is tail recursion in data structure?

If there is n consecutive execution in a recursive function, then the function will return the value to itself either 1 or n-1 times.

but in normal recursion it returns n times the value to that function.

What is the flowchart to determine if a number is an Armstrong number?

Step 1: Start

Step 2: Read n

Step 3: Temp=n

Step 4: arm=0

Step 5: If n is not equal to 0,

rem=n%0

arm=arm+(rem*rem*rem)

Step 6: n=n/10, goto 5

Step 7: If n=0, then if temp=arm, print No. is armstrong

Step 8: if temp is not equal to arm print No. is not armstrong

Step 9: Stop