answersLogoWhite

0


Best Answer

scanf() is an input function.

It takes an input from the user and store it in a variable.

Since "&" is a reference operator and it represents the memory location of the variable.

String is a type of array and an array consumes more than one memory address.
It is obvious that no need to use "&" operator for an entire array.

For an individual data type like int , char , float etc , "&" is needed but for an array no need to use "&".

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

Because the name of the string (array) is sufficient to pass the address of the first element.

By the way - it is not safe to pass strings to scanf() without doing bounds checking.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why dont you write ampersand while using strings in scanf?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Multiplication table using do while loop?

#include void main() { int i=2,m,n; printf("enter number"); scanf("%d",&n); do { m=i*n; printf("%d*%d=%d\n",n,i,m); i=i+1; } while (i<=10); }


How to write a program that ask user to enter numbers until user enter- 0 then find the biggest of entered numbers in C programming using while or do while?

int i, largest=0;do { scanf ("Enter a number (0 to exit): %d", i); if (i>largest) largest=i; } while (i!=0); printf ("Largest number is: %d\n", largest);


Do while loop program in c for printing odd numbers?

#include<stdio.h> main() { int a,i=1; printf("Enter max no"); scanf("%d",&a); do { printf("%d",i); i=i+2; }while(i<=a); }


What types of database exist in c plus plus?

#include <stdio.h> main() { FILE *a; int sno,tm,em,mm,scm,sm,hm; char sname[20],any[1]; clrscr(); a=fopen("student.dat","a"); do { printf("Enter Student Number : "); scanf("%d",&sno); printf("Enter Student Name : "); scanf("%s",sname); printf("Enter Telugu Marks : "); scanf("%d",&tm); printf("Enter English Marks : "); scanf("%d",&em); printf("Enter Maths Marks : "); scanf("%d",&mm); printf("Enter Science Marks : "); scanf("%d",&scm); printf("Enter Social Marks : "); scanf("%d",&sm); printf("Enter Hindi Marks : "); scanf("%d",&hm); fprintf(a,"%d %s %d %d %d %d %d %d\n",sno,sname,tm,em,mm,scm,sm,hm); printf("Do you wish to continue(Y/N)"); scanf("%s",any); }while(strcmp(any,"y")==0); fclose(a); }


When do we use an address operator in c'?

In C we use & operator while giving address of some variable to some pointer variable. & operator is also used in scanf().

Related questions

To compare two strings using pointers and arrays?

#includevoid main(){char str1[10],str2[10];int i=0;int flag = 0;printf("enter first string\n");scanf("%s",str1);printf("enter second string\n");scanf("%s",str2);while(str1[i]!='/0' && str2[i]!='/0'){if(str1[i]!=str2[i])flag=1;if(flag==1){printf("not equal\n");break;}if (flag==0){printf("equal\n");break;}}}


How do you make a program in C using do-while loop?

do statement; while (condition);ordo { statements } while (condition);


How do you write a C program to copy to strings using pointers?

mystrcpy (char* dest, char* src) { while ((*dest++ = *src++) != '\0); }


Where you use percent c and percent s in c language?

%c and %s are format characters used for input and output. These are mainly used in scanf and printf statements. %c is used for characters while %s is used for strings. For input, it is used to specify the type of the value to be read while for output, it is used to specify the type of the value to be printed.


What other types of strings beside nylon are used for guitars?

There are two different kind of strings. There are nylon strings and steel strings. Nylon strings are found on acoustic guitars while steel strings are common to find on electronic guitars.


How is the sound made on the cello?

By plucking the strings, drawing the bow acros the strings while fingering the frets.


Multiplication table using do while loop?

#include void main() { int i=2,m,n; printf("enter number"); scanf("%d",&n); do { m=i*n; printf("%d*%d=%d\n",n,i,m); i=i+1; } while (i<=10); }


Why are strings on a squash racquet hollow?

There are no hollow core squash racket strings, though they do exist for tennis. There are two main types of string design in strings used for squash: monofilament & multifilament. Monofilament strings are a single solid material while multifilament strings are braided and have no central core. Monofilament strings tend to be more durable but typically transfer more shock to the arm while multifilament strings have a softer feel at impact and are closer in playability to natural gut.


C program to print n prime numbers using do while loop?

#include<stdio.h> int main(){ intnum,i,count,min,max; printf("Enter min range: "); scanf("%d",&min); printf("Enter max range: "); scanf("%d",&max); num = min; while(num<=max){ count = 0; i=2; while(i<=num/2){ if(num%i==0){ count++; break; } i++; } if(count==0 && num!= 1) printf("%d ",num); num++; } return 0; }


What muscles are used while jogging in place?

the ham strings


Gwbasic program to reverse a given number using while loop.?

#include<stdio.h> #include<conio.h> void main() { int no, ans; clrscr(); printf(input no. \n"); scanf("%d", &no); while(no!=0) { n=no%10; no=no/10; printf("%d",n); } getch(); }


How to write a program that ask user to enter numbers until user enter- 0 then find the biggest of entered numbers in C programming using while or do while?

int i, largest=0;do { scanf ("Enter a number (0 to exit): %d", i); if (i>largest) largest=i; } while (i!=0); printf ("Largest number is: %d\n", largest);