Error C2040

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AlexC
    New Member
    • Apr 2010
    • 9

    Error C2040

    I'm learning programming. This program is in C, it's a simple program, but I don't know how to fix this error C2040. Error is on lines 7 & 8.
    Code:
    #include <stdio.h>
    #include <string.h>
    
    int n = 0;
    char Q[8];
    char *H, *T;
    H = Q; //error line
    T = Q;// error line
    
    int main(){
    	int choice;
    	//int count = 0;
    	
    menu:
    	printf("1 EnQ\n 2 DeQ\n 3 Print\n 4 Exit\n");
    	scanf("%d", &choice);
    	switch(choice){
    		case 1:{ 
    			EnQ();
    			goto menu;
    			   }
    		case 2:{
    			DeQ();
    			goto menu;
    			   }
    		case 3:{
    			Print();
    			goto menu;
    			   }
    		case 4:
    			return 0;
    	}
    	return 0;
    }
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    Was there a text error message that accompanied error C2040?

    Comment

    • newb16
      Contributor
      • Jul 2008
      • 687

      #3
      It's because you can't place operators outside of functions.

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Originally posted by newb16
        It's because you can't place operators outside of functions.
        Not precisely true, you can't place statements outside of functions. You can place the = operator (and others) outside of functions as part of an initialisation expression.

        Code:
        char *H = Q;    // Fine

        Comment

        • AlexC
          New Member
          • Apr 2010
          • 9

          #5
          Thanks guys for your help,
          Banfa's answer solved the problem.

          Comment

          Working...